Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Open and Close Window Programmatically Xamarin.Mac

FotalFotal Member ✭✭✭


I think this is a simple question, but I have not found the answer to it.
How can I open other windows of my application from the ViewController code?
How can I close the current window from the ViewController code?



  • FotalFotal Member ✭✭✭

    Any ideas?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    If you want to "open" a new Window, you can just instance the associated view controller and call ShowWindow:

        MySecondWindowController controller;
        public override void ViewDidLoad()
            base.ViewDidLoad ();
            controller = new MySecondWindowController ();
            controller.ShowWindow (this);

    make sure to keep the controller in scope for as long as you want the window, when it is Disposed it will close the window automatically.

    NSWindowController has a Close method on it and NSWindow has a Close as well.

    If you have not yet review the documentation and samples listed here I would consider doing so.

  • FotalFotal Member ✭✭✭
    edited February 2018

    I can't use this with storyboard, because all my UI is a related ViewControllers, I do not have a NSWindowController. I simple create Segue from other controllers and use PrepareSegue (string segueIdentifier, sender) method.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    edited February 2018

    Then I'm not sure at all what you are asking. You could create a view controller of the view you want in a new window, and root that in a new window or PrepareSegue depending on how you have it setup.

  • YuriKuznetsovYuriKuznetsov USMember ✭✭✭
    edited March 2018

    for close you can do this


    if you want to close window of current ViewController


    to open new window you can do that

    var window = new NSWindow();
  • FotalFotal Member ✭✭✭
    edited March 2018

    Ok @YuriKuznetsov i will try this later, thanks

Sign In or Register to comment.