Skip to content

Commit

Permalink
Add sample to trigger an animation using the AnimateCommand (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
bijington authored Nov 29, 2023
1 parent 69cb515 commit f689af3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@

<Frame BackgroundColor="LightGreen" Margin="16,0">
<Frame.Behaviors>
<mct:AnimationBehavior Command="{Binding AnimationCommand}">
<mct:AnimationBehavior AnimateCommand="{Binding AnimateFromViewModelCommand}">
<mct:AnimationBehavior.AnimationType>
<mct:FadeAnimation Opacity="0.2" />
</mct:AnimationBehavior.AnimationType>
</mct:AnimationBehavior>
</Frame.Behaviors>
<Label Text="Click this Frame" HorizontalOptions="Center"/>
</Frame>

<Button Text="Animate the frame above" Command="{Binding TriggerAnimationCommand}" />
</VerticalStackLayout>
</pages:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ public partial class AnimationBehaviorViewModel : BaseViewModel
{
[RelayCommand]
Task OnAnimation(CancellationToken token) => Snackbar.Make($"{nameof(AnimationCommand)} is triggered.").Show(token);

public ICommand? AnimateFromViewModelCommand { get; set; }

[RelayCommand]
void OnTriggerAnimation()
{
AnimateFromViewModelCommand?.Execute(CancellationToken.None);
}
}

0 comments on commit f689af3

Please sign in to comment.