Share via

Binding refresh counter smoootly

Dani_S 5,581 Reputation points
2023-09-14T13:12:51.5+00:00

Hi,

Please see https://app.screencast.com/itMCskOJqMYAL

The finished counter value change its value from zero to new value.

In the begging of the loop the value is zero of finished counter and later when the loop it finished it get it real value.

How i can avoid this "change" to be smoothly?

Thanks,

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author

Anonymous
2023-09-19T08:50:35.6166667+00:00

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.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.