0
votes

I have two customized NSWindow in my application like these:

Window 1:

public partial class LoginVindow : NSWindow
    {
        public LoginVindow (IntPtr handle) : base (handle)
        {
        }
    }

Window 1

Window 2:

public partial class OperationWindow : NSWindow
    {
        public OperationWindow (IntPtr handle) : base (handle)
        {
        }
    }

Window 2

Now, I want close the first Window after a button click and open the second Window. However, this code cannot run for me.

 partial void LoginButton_Clicked(Foundation.NSObject sender)
    {
        Window.Close(); // Closes the first login window.

        var operation_window = new OperationWindow(Handle); // Gets the second Window. IntPtr parameter is required unlike the internet codeblocks.

        operation_window.ShowWindow(this); // No any method like this.
    }

All of the code blocks over internet seems for non-customized standard class NSWindow items but one of them is seems stable for me. However, it is not running. (Post in Xamarin Forums: https://forums.xamarin.com/discussion/122359/open-and-close-window-programmatically-xamarin-mac)

How can I handle this operation ? Please help, thanks.

1
You do not ShowWindow via the NSWindow itself, you show it via the a NSWindowController as the NSWindow is owned by the NSWindowController ( yourWindowController.ShowWindow(yourAppDel);)SushiHangover
How can I define a NSWindowController via Code? For example, the Window 1 is the starting point and show automatically by app. Is it a automatic Window controller? @SushiHangoverberkb
Also, the constructor wants IntPtr input for me like: LoginWindowController (IntPtr handle). I cannot solve how can I make the controller live. Which type of IntPtr should I use ? @SushiHangoverberkb

1 Answers

0
votes

This code block fixed my problem. Thanks.

    // Get new window
    var storyboard = NSStoryboard.FromName("Main", null);
    var controller = storyboard.InstantiateControllerWithIdentifier("OperationsWindow") as NSWindowController;
    controller.ShowWindow(this);
    this.Window.Close();