How will open an application in full screen mode.

Udit1Udit1 Member ✭✭

Hi,

When ever I run my application, it must be open in full screen mode. How will do it?

Thanks

Tagged:

Best Answers

  • JGoldbergerJGoldberger US Xamurai
    Accepted Answer

    @Udit1

    You need to get a reference to your window and then call ToggleFullSreen method, e.g.:

    NSWindow window = NSApplication.SharedApplication.Windows[0];
    window.ToggleFullScreen(this);
    

    And you can also subscribe to events for when the app goes in and out of full screen (i.e. use clicks the green full screen button):

     window.DidEnterFullScreen += Window_DidEnterFullScreen;
     window.DidExitFullScreen += Window_DidExitFullScreen;
    
     void Window_DidEnterFullScreen(object sender, EventArgs e)
        {
            // Do stuff
        }
    
        void Window_DidExitFullScreen(object sender, EventArgs e)
        {
            // Do stuff
        }
    

Answers

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai

    For Xamarin.Android, full screen means you need set Activity full screen, you could refer to:

  • Udit1Udit1 Member ✭✭

    Thanks for reply. But I need this for Mac OS High Sierra.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    Accepted Answer

    @Udit1

    You need to get a reference to your window and then call ToggleFullSreen method, e.g.:

    NSWindow window = NSApplication.SharedApplication.Windows[0];
    window.ToggleFullScreen(this);
    

    And you can also subscribe to events for when the app goes in and out of full screen (i.e. use clicks the green full screen button):

     window.DidEnterFullScreen += Window_DidEnterFullScreen;
     window.DidExitFullScreen += Window_DidExitFullScreen;
    
     void Window_DidEnterFullScreen(object sender, EventArgs e)
        {
            // Do stuff
        }
    
        void Window_DidExitFullScreen(object sender, EventArgs e)
        {
            // Do stuff
        }
    
  • Udit1Udit1 Member ✭✭

    @Goldberger

    Following code given by you is helpful.

    NSWindow window = NSApplication.SharedApplication.Windows[0];
    window.ToggleFullScreen(this);

    But some piece of code in my project is creating problem. Actually I am launching two window (Stellar MBOX to PST window and Select MBOX window) on same time. For this I am using following code to display second window(Select MBox)...

        BeginInvokeOnMainThread(() =>
            {
               //On commenting the below line window is displaying in full screen mode. 
               NSApplication.SharedApplication.RunModalForWindow(mboxBrowsController.Window);
            });
    

    As you will see AwakeFromNib() function in MainWindowController.cs file. If I comment "NSApplication.SharedApplication.RunModalForWindow(mboxBrowsController.Window);" than ToggleFullScreen(this); working fine.

    For this I am attaching my sample code. Kindly download from your message box.

  • Udit1Udit1 Member ✭✭

    @Goldberger

    Following code is helpful for first time launching main window in full screen mode.

    NSWindow window = NSApplication.SharedApplication.Windows[0];
    window.ToggleFullScreen(this);

    But I have a another scenario in which I am facing problem.

    After launching the app in full screen mode follow bellow steps....

    1. Close the Select MBOX window.
    2. Click green button in top of left side of Stellar MBOX to PST Converter window to exit from full screen mode.
    3. Again set Stellar MBOX to PST Converter window in full screen mode.
    4. Click Open Button to display Select MBOX window.

    When Click on Open Button (in left side of Tool Bar) OpenDialog(NSObject sender) function will be invoke .

    This time also process is being stuck.

    Thanks

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @Udit1

    The app is not stuck, the MBOX window just opens on another desktop. When you go full screen, a new desktop is created. You can go back to your original desktop using Mission Control or CTL-left/right arrow to switch desktops. On my end with your app as is, once I did go back to the Desktop that the MBOX window opened on, it moved back to the full screen desktop, which is annoying. Anyway, to work around this, just explicitly set the frame of your new window in the OpenDialog method, e.g.:

    partial void OpenDialog(NSObject sender)
        {
            if(mboxBrowsController == null)
            {
                mboxBrowsController = new MBoxBrowserController();
            }
    
            // Added
            var modWinRect = mboxBrowsController.Window.Frame;
    
            var newModWinRect = new CoreGraphics.CGRect(
                0, 0,
                modWinRect.Size.Width,
                modWinRect.Size.Height
            );
    
            mboxBrowsController.Window.SetFrame(newModWinRect, false);
            // End added 
    
            BeginInvokeOnMainThread(() =>
            {
                NSApplication.SharedApplication.RunModalForWindow(mboxBrowsController.Window);
            });
    }
    
  • Udit1Udit1 Member ✭✭

    Hi,

    I tried above but not working. Is there another way.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @Udit1

    What exactly is not working? Can you provide an updated solution so I can check to see what is going on?

  • Udit1Udit1 Member ✭✭

    When application run first time its work fine. Even I close and reopen Select MBOX window, It works perfectly. But when ever I close Select MBOX window and then exit full screen mode and once again enter to full screen mode and then open Select MBOX window by clicking on Open button. That time it is not working.

  • Udit1Udit1 Member ✭✭

    I will upload the code also.

Sign In or Register to comment.