A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello,
Add the easing animation to the Label when label's text changing.
You can do this by Behavior, when this Text property changing, this label will have an animation. You can refer to the following link.
public class BlinkTriggerBehavior : Behavior<VisualElement>
{
protected override void OnAttachedTo(VisualElement bindable)
{
base.OnAttachedTo(bindable);
bindable.PropertyChanging += Bindable_PropertyChanging; ; // binding property changed event
}
private async void Bindable_PropertyChanging(object sender, Microsoft.Maui.Controls.PropertyChangingEventArgs e)
{
//throw new NotImplementedException();
// your animation code gets fired everytime any of your Label
// property changes or any VisualElement which uses this behavior.
if (e.PropertyName == "Text")
{
Label label = sender as Label;
await label.FadeTo(0, 200).ContinueWith(async (o, e) => { await label.FadeTo(1, 500); }, label);
}
}
protected override void OnDetachingFrom(VisualElement bindable)
{
base.OnDetachingFrom(bindable);
bindable.PropertyChanging -= Bindable_PropertyChanging;
}
}
Please set this in OnAppearing method.
protected override void OnAppearing()
{
base.OnAppearing();
Mylabel.Behaviors.Add(new BlinkTriggerBehavior());
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.