I have codes to migrating to net maui I have some notifications how to set this ?

Sami 261 Reputation points
public class FadeInAnimation : AnimationBase  
    public enum FadeDirection  

    public static readonly BindableProperty DirectionProperty =  
        BindableProperty.Create(nameof(Direction), typeof(FadeDirection), typeof(FadeInAnimation), FadeDirection.Up,  
            BindingMode.TwoWay, null);  

    public FadeDirection Direction  
        get { return (FadeDirection)GetValue(DirectionProperty); }  
        set { SetValue(DirectionProperty, value); }  

    protected override Task BeginAnimation()  
        if (Target == null)  
            throw new NullReferenceException("Null Target property.");  

        return Task.Run(() =>  
            Device.BeginInvokeOnMainThread(() =>  
                Target.Animate("FadeIn", FadeIn(), 16, Convert.ToUInt32(Duration));  

    internal Animation FadeIn()  
        var animation = new Animation();  

        animation.WithConcurrent((f) => Target.Opacity = f, 0, 1, Microsoft.Maui.Easing.CubicOut);  

          (f) => Target.TranslationY = f,  
          Target.TranslationY + ((Direction == FadeDirection.Up) ? 50 : -50), Target.TranslationY,  
          Microsoft.Maui.Easing.CubicOut, 0, 1);  

        return animation;  

Warning CS0618 'Device.BeginInvokeOnMainThread(Action)' is obsolete: 'Use BindableObject.Dispatcher.Dispatch() instead.'

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
1,384 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 19,891 Reputation points Microsoft Vendor

    Hello @Sami ,

    You can check the similar thread - How do you use BindableObject.Dispatcher.DispatchAsync() in .NET MAUI? - Microsoft Q&A
    Microsoft.Maui.Controls.BindableObject is MAUI's root class for objects that can be bound - it is very high in the MAUI class hierarchy, and almost all MAUI objects inherit from it. See Data Binding Basic.

    From the code snippets, it's not clear to me what type of your AnimationBase is, it might derive from View or Layout or other Microsoft.Maui.Controls. Since there is a bindable property, it means that the target object ( AnimationBase ) must derive from BindableObject. BindableObject have a Dispatcher property which can be used to get access to the main thread. You could try

    this.Dispatcher.Dispatch(() =>  

    For more details, you can check Dispatcher.Dispatch(Action) Method (Microsoft.Maui.Dispatching) | Microsoft Learn
    and BindableObject.Dispatcher Property (Microsoft.Maui.Controls) | Microsoft Learn

    Best Regards,
    Wenyan Zhang

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful