I'm writing Xamarin application and I found difference between WPF which I cannot cross.
I'm using Xamarin Forms Labs to get Repeater control.
I have a Repeater, which repeats DataTemplate:
<DataTemplate>
<Button Text="{Binding Text}" Command="{Binding CategorySelectedCommand}" />
</DataTemplate>
But i would like to move command execution to my userControl Binding Context.
Normally with WPF it would look like:
Command={Binding ElementName=myUserControl, Path=DataContext.CategorySelectedCommand}
But it does not have ElementName property.
I have found that I could set BindingContext of my button like this:
BindingContext="{x:Reference myUserControl}"
But then I cannot bind Text property to my button's text.
How should I do this?
You can use the
Source
property to specify a source for the binding that will be used instead of the currentBindingContext
. Then the text can come from the page's binding context and the command from somewhere else.or
or
Here's a complete example. A common problem is to not implement
INotifyPropertyChanged
and set the property after the call toInitializeComponent()
.XAML
Code behind