Last active
June 24, 2019 11:03
-
-
Save hamid-shaikh/62778ddd4e97b994e5991856bae6ba01 to your computer and use it in GitHub Desktop.
TapToCommandBehavior usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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