Changes

Xamarin XAML

1,430 bytes added, 12:45, 10 May 2023
/* Known issues */
</classes:KeyValueList>
</Button.CommandParameter>
</Button>
</syntaxhighlight>
 
=== Buttons and gesture recognizers ===
In Xamarin XAML, you can use gesture recognizers on many UI elements such as a Grid to enable the latter to interact with user inputs.
 
However, we've already made quite a lot of experience that gesture recognizers do not always work on Android and iOS when used on a Button control.
For example, the following Button won't properly invoke the command on said platforms.
 
<syntaxhighlight lang="xml">
<!-- THIS DOESN'T WORK!!! -->
<Button ...>
<Button.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ReplicateAsDataCommand}" />
</Button.GestureRecognizers>
</Button>
</syntaxhighlight>
 
<br/>
Therefore, you should always seek alternatives for Buttons.
If only one command is needed, use the standard Command property on the Button, e.g.
 
<syntaxhighlight lang="xml">
<!-- THIS WORKS -->
<Button Command="{Binding ReplicateAsDataCommand}" .../>
</syntaxhighlight>
 
<br/>
Or if multiple commands are needed, use Behaviors instead, e.g.
 
<syntaxhighlight lang="xml">
<!-- THIS ALSO WORKS -->
<Button xmlns:behaviors="clr-namespace:UBIK.CPL.Behaviors;assembly=UBIK.CPL" ...>
<Button.Behaviors>
<behaviors:EventToCommandBehavior Command="{Binding ReplicateAsDataCommand}" EventName="Clicked" />
<behaviors:EventToCommandBehavior Command="{Binding NavigateBackCommand}" EventName="Clicked" />
</Button.Behaviors>
</Button>
</syntaxhighlight>