Xamarin Forms User Control: Forward Entry.Behaviors dependency property in composite control












0















I created a user control in which I placed an Xamarin.Forms Entry. The idea is to wrap the original Entry with some additional funtionality such as an input validation error, images, etc... and use the composite control all over my Xamarin.Forms app. Nothing special so far.



All relevant dependency properties of Entry are forwarded to the wrapping composite control, e.g. Text, Style. Now, the problem comes when I want to expose a dependency property for Behavoirs which I want to forward to the nested Entry control.



Does anyone have experience in “forwarding” nested dependency properties, in particular with Behaviors?



Update 2018-11-25:



ValidatableEntry.xaml is a Grid which contains the nested Entry control. Text and Placeholder properties of Entry are bound to local dependency properties, I call this approach "property forwarding".



<?xml version="1.0" encoding="UTF-8"?>
<Grid
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ValidatableEntry"
x:Name="Control">

<Entry
Grid.Row="0"
x:Name="Entry"
Text="{Binding Text, Source={x:Reference Control}, Mode=TwoWay}"
Placeholder="{Binding Placeholder, Source={x:Reference Control}, Mode=OneWay}">

</Entry>
</Grid>


ValidatableEntry.xaml.cs contains the exposed dependency properties, TextPropery and PlaceholderProperty. The question is: How can I forward the Behaviors property? I tried following, which doesn't work:



 public new static readonly BindableProperty BehaviorsProperty =
BindableProperty.Create(
nameof(Behaviors),
typeof(IList<Behavior>),
typeof(ValidatableEntry),
default(IList<Behavior>),
BindingMode.OneWayToSource);

public new IList<Behavior> Behaviors
{
get { return (IList<Behavior>)this.Entry.GetValue(VisualElement.BehaviorsProperty); }
}









share|improve this question

























  • Can you provide some code to explain better what you're saying ?

    – FabriBertani
    Nov 24 '18 at 22:58











  • Yep. This is a good idea. I’ll be back with a condensed snipped.

    – thomasgalliker
    Nov 25 '18 at 0:04
















0















I created a user control in which I placed an Xamarin.Forms Entry. The idea is to wrap the original Entry with some additional funtionality such as an input validation error, images, etc... and use the composite control all over my Xamarin.Forms app. Nothing special so far.



All relevant dependency properties of Entry are forwarded to the wrapping composite control, e.g. Text, Style. Now, the problem comes when I want to expose a dependency property for Behavoirs which I want to forward to the nested Entry control.



Does anyone have experience in “forwarding” nested dependency properties, in particular with Behaviors?



Update 2018-11-25:



ValidatableEntry.xaml is a Grid which contains the nested Entry control. Text and Placeholder properties of Entry are bound to local dependency properties, I call this approach "property forwarding".



<?xml version="1.0" encoding="UTF-8"?>
<Grid
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ValidatableEntry"
x:Name="Control">

<Entry
Grid.Row="0"
x:Name="Entry"
Text="{Binding Text, Source={x:Reference Control}, Mode=TwoWay}"
Placeholder="{Binding Placeholder, Source={x:Reference Control}, Mode=OneWay}">

</Entry>
</Grid>


ValidatableEntry.xaml.cs contains the exposed dependency properties, TextPropery and PlaceholderProperty. The question is: How can I forward the Behaviors property? I tried following, which doesn't work:



 public new static readonly BindableProperty BehaviorsProperty =
BindableProperty.Create(
nameof(Behaviors),
typeof(IList<Behavior>),
typeof(ValidatableEntry),
default(IList<Behavior>),
BindingMode.OneWayToSource);

public new IList<Behavior> Behaviors
{
get { return (IList<Behavior>)this.Entry.GetValue(VisualElement.BehaviorsProperty); }
}









share|improve this question

























  • Can you provide some code to explain better what you're saying ?

    – FabriBertani
    Nov 24 '18 at 22:58











  • Yep. This is a good idea. I’ll be back with a condensed snipped.

    – thomasgalliker
    Nov 25 '18 at 0:04














0












0








0








I created a user control in which I placed an Xamarin.Forms Entry. The idea is to wrap the original Entry with some additional funtionality such as an input validation error, images, etc... and use the composite control all over my Xamarin.Forms app. Nothing special so far.



All relevant dependency properties of Entry are forwarded to the wrapping composite control, e.g. Text, Style. Now, the problem comes when I want to expose a dependency property for Behavoirs which I want to forward to the nested Entry control.



Does anyone have experience in “forwarding” nested dependency properties, in particular with Behaviors?



Update 2018-11-25:



ValidatableEntry.xaml is a Grid which contains the nested Entry control. Text and Placeholder properties of Entry are bound to local dependency properties, I call this approach "property forwarding".



<?xml version="1.0" encoding="UTF-8"?>
<Grid
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ValidatableEntry"
x:Name="Control">

<Entry
Grid.Row="0"
x:Name="Entry"
Text="{Binding Text, Source={x:Reference Control}, Mode=TwoWay}"
Placeholder="{Binding Placeholder, Source={x:Reference Control}, Mode=OneWay}">

</Entry>
</Grid>


ValidatableEntry.xaml.cs contains the exposed dependency properties, TextPropery and PlaceholderProperty. The question is: How can I forward the Behaviors property? I tried following, which doesn't work:



 public new static readonly BindableProperty BehaviorsProperty =
BindableProperty.Create(
nameof(Behaviors),
typeof(IList<Behavior>),
typeof(ValidatableEntry),
default(IList<Behavior>),
BindingMode.OneWayToSource);

public new IList<Behavior> Behaviors
{
get { return (IList<Behavior>)this.Entry.GetValue(VisualElement.BehaviorsProperty); }
}









share|improve this question
















I created a user control in which I placed an Xamarin.Forms Entry. The idea is to wrap the original Entry with some additional funtionality such as an input validation error, images, etc... and use the composite control all over my Xamarin.Forms app. Nothing special so far.



All relevant dependency properties of Entry are forwarded to the wrapping composite control, e.g. Text, Style. Now, the problem comes when I want to expose a dependency property for Behavoirs which I want to forward to the nested Entry control.



Does anyone have experience in “forwarding” nested dependency properties, in particular with Behaviors?



Update 2018-11-25:



ValidatableEntry.xaml is a Grid which contains the nested Entry control. Text and Placeholder properties of Entry are bound to local dependency properties, I call this approach "property forwarding".



<?xml version="1.0" encoding="UTF-8"?>
<Grid
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ValidatableEntry"
x:Name="Control">

<Entry
Grid.Row="0"
x:Name="Entry"
Text="{Binding Text, Source={x:Reference Control}, Mode=TwoWay}"
Placeholder="{Binding Placeholder, Source={x:Reference Control}, Mode=OneWay}">

</Entry>
</Grid>


ValidatableEntry.xaml.cs contains the exposed dependency properties, TextPropery and PlaceholderProperty. The question is: How can I forward the Behaviors property? I tried following, which doesn't work:



 public new static readonly BindableProperty BehaviorsProperty =
BindableProperty.Create(
nameof(Behaviors),
typeof(IList<Behavior>),
typeof(ValidatableEntry),
default(IList<Behavior>),
BindingMode.OneWayToSource);

public new IList<Behavior> Behaviors
{
get { return (IList<Behavior>)this.Entry.GetValue(VisualElement.BehaviorsProperty); }
}






forms xamarin xamarin.forms dependency-properties behavior






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 18:26







thomasgalliker

















asked Nov 24 '18 at 20:02









thomasgallikerthomasgalliker

7610




7610













  • Can you provide some code to explain better what you're saying ?

    – FabriBertani
    Nov 24 '18 at 22:58











  • Yep. This is a good idea. I’ll be back with a condensed snipped.

    – thomasgalliker
    Nov 25 '18 at 0:04



















  • Can you provide some code to explain better what you're saying ?

    – FabriBertani
    Nov 24 '18 at 22:58











  • Yep. This is a good idea. I’ll be back with a condensed snipped.

    – thomasgalliker
    Nov 25 '18 at 0:04

















Can you provide some code to explain better what you're saying ?

– FabriBertani
Nov 24 '18 at 22:58





Can you provide some code to explain better what you're saying ?

– FabriBertani
Nov 24 '18 at 22:58













Yep. This is a good idea. I’ll be back with a condensed snipped.

– thomasgalliker
Nov 25 '18 at 0:04





Yep. This is a good idea. I’ll be back with a condensed snipped.

– thomasgalliker
Nov 25 '18 at 0:04












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461900%2fxamarin-forms-user-control-forward-entry-behaviors-dependency-property-in-compo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461900%2fxamarin-forms-user-control-forward-entry-behaviors-dependency-property-in-compo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft