Xamarin.Forms.Behaviors
Xamarin.Forms.Behaviors copied to clipboard
EventToCommand on GestureRecognizers
Trying to use EventToCommand with GestureRecognizers, no success with CommandParameter, here is the example:
<ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal" Padding="10" >
<Label Text="{Binding NickName}">
<Label.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand CommandNameContext="{b:RelativeContext MainPage}"
EventName="Tapped"
CommandName="NickSelectedCommand"
CommandParameter="{Binding NickName}" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</TapGestureRecognizer>
</Label.GestureRecognizers>
</Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
If you took off the
Unfortunately TapGestureRecognizer doesn't inherit the BindingContext so EventToCommand's BindingContext is null and CommandParameter's binding fails, that's where the null comes from. Being part of GestureRecognizers collection there's no way to reach Label's BindingContext.
Xamarin Forms limitation, I hope someday they can do something about.
Tks Corrado
Em 08/10/2014, à(s) 13:27, Corrado Cavalli [email protected] escreveu:
Unfortunately TapGestureRecognizer doesn't inherit the BindingContext so EventToCommand's BindingContext is null and CommandParameter's binding fails, that's where the null comes from. Being part of GestureRecognizers collection there's no way to reach Label's BindingContext.
— Reply to this email directly or view it on GitHub.
Looks like, Xamarin Forms will support behaviors soon http://forums.xamarin.com/discussion/25612/xamarin-forms-1-3-0-technology-preview
Em 08/10/2014, à(s) 14:29, Alexandre [email protected] escreveu:
Xamarin Forms limitation, I hope someday they can do something about.
Tks Corrado
Em 08/10/2014, à(s) 13:27, Corrado Cavalli [email protected] escreveu:
Unfortunately TapGestureRecognizer doesn't inherit the BindingContext so EventToCommand's BindingContext is null and CommandParameter's binding fails, that's where the null comes from. Being part of GestureRecognizers collection there's no way to reach Label's BindingContext.
— Reply to this email directly or view it on GitHub.
I see, cool, let's see their implementation...
<Label.GestureRecognizers> <TapGestureRecognizer BindingContext="{behaviors:RelativeContext MyClassName}" Command="{Binding MyCmd}" </Label.GestureRecognizers>