Forum Xamarin.Mac

SplashScreen Implementation : Issue in implmentation of splash screen

pnerkarpnerkar Member ✭✭
edited September 15 in Xamarin.Mac

I created XIB for Splashscreen ( view : NsWindow , ViewContoller : NsWindowcontroller)

and using WillFinishLaunching

public override void WillFinishLaunching(NSNotification notification)
    {
        splashScreenController = new SplashScreenWindowController();

        if (splashScreenController != null)
        {
            if (splashScreenController.Window != null)
                splashScreenController.Window.OrderFrontRegardless();
        }


        Thread.Sleep(5000);
    }


  public override void DidFinishLaunching(NSNotification notification)
   {
        splashScreenController.Window.OrderOut(null);

  }


public partial class SplashScreenWindowController : NSWindowController
{
    #region Constructors


    public SplashScreenWindowController(IntPtr handle) : base(handle)
    {
    }

    // Call to load from the XIB/NIB file
    public SplashScreenWindowController() : base("SplashScreen")
    {

    }

    #endregion

    public override void WindowDidLoad()
    {
        base.WindowDidLoad();
        Window.HasShadow = false;
        Window.IsOpaque = false;
        Window.BackgroundColor = NSColor.Clear;
        Window.Level = NSWindowLevel.Status;
    }

    public new SplashScreen Window
    {
        get { return (SplashScreen)base.Window; }
    }
}
}

I am always getting null reference exception , Window is coming null

Please let us know if it is correct way to implement to Splash screen or if I am missing something

Tagged:

Best Answer

  • pnerkarpnerkar Member ✭✭
    Accepted Answer

    I am still getting null reference exception on WindowDidLoad , Window object is coming null, Below is my WindowController class and Splash window class

    public partial class SplashScreenWindowController : NSWindowController
    {
    #region Constructors

        public SplashScreenWindowController(IntPtr handle) : base(handle)
        {
        }
    
        // Call to load from the XIB/NIB file
        public SplashScreenWindowController() : base("SplashScreen")
        {
    
        }
    
        #endregion
    
        public override void WindowDidLoad()
        {
            base.WindowDidLoad();
            Window.HasShadow = false;
            Window.IsOpaque = false;
            Window.BackgroundColor = NSColor.Clear;
            Window.Level = NSWindowLevel.Status;
        }
    
        public new SplashScreen Window
        {
            get { return (SplashScreen)base.Window; }
        }
    }
    

    //SplashWindow
    public partial class SplashScreen : NSWindow
    {
    #region Constructors

        public SplashScreen(IntPtr handle) : base(handle)
        {
    
        }
    
        #endregion
    }
    

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 15

    Refer to the github sample , i convert it from swift to C#.

    [Register("AppDelegate")]
    public class AppDelegate : NSApplicationDelegate
    {       
    
        public AppDelegate()
        {
        }
    
        public override void DidFinishLaunching(NSNotification notification)
        {
    
            SplashWindowController window = new SplashWindowController();
            window.ShowWindow(this);
    
    
            NSOperationQueue operationQueue = new NSOperationQueue();
    
            NSBlockOperation startUpCompletionOperation = NSBlockOperation.Create(() =>
            {
    
                NSOperationQueue.MainQueue.AddOperation(NSBlockOperation.Create(() =>
                {
                    window.Close();
    
                }));
            });
    
    
            NSBlockOperation startUpOperation = NSBlockOperation.Create(() =>
            {
                Thread.Sleep(3000);
                operationQueue.AddOperation(startUpCompletionOperation);
            });
    
    
            startUpCompletionOperation.AddDependency(startUpOperation);            
            operationQueue.AddOperation(startUpOperation);
    
    
        }
    }
    
  • pnerkarpnerkar Member ✭✭
    Accepted Answer

    I am still getting null reference exception on WindowDidLoad , Window object is coming null, Below is my WindowController class and Splash window class

    public partial class SplashScreenWindowController : NSWindowController
    {
    #region Constructors

        public SplashScreenWindowController(IntPtr handle) : base(handle)
        {
        }
    
        // Call to load from the XIB/NIB file
        public SplashScreenWindowController() : base("SplashScreen")
        {
    
        }
    
        #endregion
    
        public override void WindowDidLoad()
        {
            base.WindowDidLoad();
            Window.HasShadow = false;
            Window.IsOpaque = false;
            Window.BackgroundColor = NSColor.Clear;
            Window.Level = NSWindowLevel.Status;
        }
    
        public new SplashScreen Window
        {
            get { return (SplashScreen)base.Window; }
        }
    }
    

    //SplashWindow
    public partial class SplashScreen : NSWindow
    {
    #region Constructors

        public SplashScreen(IntPtr handle) : base(handle)
        {
    
        }
    
        #endregion
    }
    
  • ColeXColeX Member, Xamarin Team Xamurai

    Check my sample below.

Sign In or Register to comment.