Skip to content

Instantly share code, notes, and snippets.

@hamid-shaikh
Last active June 24, 2019 11:03
Show Gist options
  • Save hamid-shaikh/62778ddd4e97b994e5991856bae6ba01 to your computer and use it in GitHub Desktop.
Save hamid-shaikh/62778ddd4e97b994e5991856bae6ba01 to your computer and use it in GitHub Desktop.
TapToCommandBehavior usage example
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:appBehaviors="clr-namespace:ProjectName.Mobile.Behaviors"
x:Class="ProjectName.Mobile.Views.TestPage">
<!--ContentPage Content-->
<Grid
BackgroundColor="{StaticResource whiteColor}"
RowSpacing="0"
ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Image
VerticalOptions="EndAndExpand"
DownsampleToViewSize="true"
Aspect="AspectFit"
HeightRequest="270"
Grid.Row="1"
Source="someIcon.png">
<Image.Behaviors>
<appBehaviors:TapToCommandBehavior
TapCommand="{Binding SomeViewModelCommand}"
TapCommandParameter="{Binding SomePropert}" /> <!--You can also specify some static value-->
</Image.Behaviors>
</Image>
<StackLayout
x:Name="parentStackLayout"
Margin="24, 0"
VerticalOptions="EndAndExpand"
Spacing="30">
<Label
VerticalOptions="Center"
Text="Label Text"
Style="{StaticResource primaryLabelStyle}">
<Label.Behaviors>
<appBehaviors:TapToCommandBehavior
TapCommand="{Binding SomeViewModelCommand}"
TapCommandParameter="{Binding SomePropert}"
ViewToAnimateOnTap="{x:Reference parentStackLayout}" /> <!--Please note parentStackLayout will animate when Label is tapped-->
</Label.Behaviors>
</Label>
<Button
Text="Button Text"
Style="{StaticResource primaryButtonStyle}">
<Button.Behaviors>
<appBehaviors:TapToCommandBehavior
TapCommand="{Binding SomeViewModelCommand}"
TapCommandParameter="{Binding SomePropert}"
ViewToAnimateOnTap="{x:Reference parentStackLayout}" /> <!--Please note parentStackLayout will animate when Label is tapped-->
</Button.Behaviors>
</Button>
</StackLayout>
</Grid>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment