Skip to content

Commit

Permalink
Fix animation behavior hot reload (#2288)
Browse files Browse the repository at this point in the history
* Add missing setter for AnimateCommand

Fix https://developercommunity.visualstudio.com/t/Hot-reload-stops-working-when-using-Comm/10707756

Control properties should have both a getter and setter
so that Hot Reload (and C# code) can update them.
AnimateCommand was missing the setter - likely just
an oversight. Hot Reload now works with this change.

* Add comment clarifying that apps shouldn't use the setter directly.

* Attempt to make thr setter as  obsolete

* Update AnimationBehavior.shared.cs

* Update AnimationBehavior.shared.cs

---------

Co-authored-by: Shaun Lawrence <[email protected]>
  • Loading branch information
BretJohnson and bijington authored Oct 17, 2024
1 parent 660ce05 commit a9ab301
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/CommunityToolkit.Maui/Behaviors/AnimationBehavior.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,27 @@ public class AnimationBehavior : EventToCommandBehavior

/// <summary>
/// Gets the Command that allows the triggering of the animation.
///
/// NOTE: Apps should not directly set this property, treating it as read only. The setter is only public because
/// that's currently needed to make XAML Hot Reload work. Instead, apps should provide a value for this OneWayToSource
/// property by creating a binding, in XAML or C#. If done via C# use code like this:
/// <c>behavior.SetBinding(AnimationBehavior.AnimateCommandProperty, nameof(ViewModel.TriggerAnimationCommand));</c>
/// </summary>
/// <remarks>
/// <see cref="AnimateCommand"/> has a <see cref="Type"/> of Command&lt;CancellationToken&gt; which requires a <see cref="CancellationToken"/> as a CommandParameter. See <see cref="Command{CancellationToken}"/> and <see cref="System.Windows.Input.ICommand.Execute(object)"/> for more information on passing a <see cref="CancellationToken"/> into <see cref="Command{T}"/> as a CommandParameter"
/// </remarks>
public Command<CancellationToken> AnimateCommand => (Command<CancellationToken>)GetValue(AnimateCommandProperty);
public Command<CancellationToken> AnimateCommand {
get => (Command<CancellationToken>)GetValue(AnimateCommandProperty);
[Obsolete(
"""
Do not use this setter, it only exists to enable XAML Hot reload support in your IDE.
Instead, apps should provide a value for this OneWayToSource property by creating a binding, in XAML or C#. If done via C# use code like this:
behavior.SetBinding(AnimationBehavior.AnimateCommandProperty, nameof(ViewModel.TriggerAnimationCommand));
""")]
set => SetValue(AnimateCommandProperty, value);
}

/// <summary>
/// The type of animation to perform.
Expand Down

0 comments on commit a9ab301

Please sign in to comment.