Full screen mode in Windows 10 Universal apps

Full screen mode in Windows 10 Universal apps

Windows 10 Universal apps can run both in full screen mode and windowed mode (window can be maximized/resized when not in full screen mode). This means that we have new APIs to use and set the mode programmatically. ApplicationView class is extended with new properties and methods which makes it really easy to determine whether the app is running in full screen mode or not, and to change it (or at least try to!).

Note that that the samples in this blog post work on Windows 10 Technical Preview build 10130 and Technical Preview Tools, so things can change in the future.

Here's a quick example that checks if the app is in full screen mode. If it is, we exit the full screen mode, and if it's not, we enter it. So basically, if this is executed on button click event, the button will toggle the full screen mode.

ApplicationView view = ApplicationView.GetForCurrentView();

bool isInFullScreenMode = view.IsFullScreenMode;

if (isInFullScreenMode)  
{
    view.ExitFullScreenMode();
}
else  
{
    view.TryEnterFullScreenMode();
}

The meaning of the new IsFullScreenMode boolean is quite obvious - it tells us if the current window is in full screen mode. There are also 2 new methods, ExitFullScreenMode for exiting the full screen mode, and TryEnterFullScreenMode for entering the full screen mode. The latter can fail, so it returns a bool to tell you if it succeeded or not. However, even if it works OK and the method returns true, the window may not still be in full screen mode. To actually know when entering to, or exiting from the full screen mode has completed, you need to subscribe to Window.Current.SizeChanged.

We can write a small state trigger based on all this, called IsInFullScreenModeTrigger.

public class IsFullScreenModeTrigger : StateTriggerBase  
{
    public IsFullScreenModeTrigger()
    {
        ApplicationView view = ApplicationView.GetForCurrentView();

        SetActive(view.IsFullScreenMode);

        Window.Current.SizeChanged += CurrentWindow_SizeChanged;
    }

    private void CurrentWindow_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        ApplicationView view = ApplicationView.GetForCurrentView();

        SetActive(view.IsFullScreenMode);
    }
}

And use it in XAML like this:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState x:Name="InFullScreen">
                <VisualState.StateTriggers>
                    <local:IsFullScreenModeTrigger />
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="IsFullScreenText.Text" Value="In full screen mode" />
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <StackPanel HorizontalAlignment="Center">
        <Button Click="Button_Click" 
                Content="Toggle full screen"></Button>
        <TextBlock x:Name="IsFullScreenText" 
                    FontSize="72" 
                    TextWrapping="Wrap" 
                    Text="Not in full screen mode"/>
    </StackPanel>
</Grid>  

Preferred launch windowing mode

It's also possible to set a preferred launch windowing mode by setting the static property on ApplicationView called PreferredLaunchWindowingMode.

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;  

PreferredLaunchWindowingMode is of type ApplicationViewWindowingMode which can be set to Auto (0), PreferredLaunchViewSize (1) or FullScreen (2). Setting it to PreferredLaunchViewSize means that the window will be sized based on ApplicationView.PreferredLaunchViewSize size. If you haven't set the ApplicationView.PreferredLaunchViewSize, Windows will use the latest size it remembers.

Full screen mode - hides the taskbar and title bar
App running in full screen mode

Windowed mode
App running in windowed mode

Conclusion

Windows 10 brings very simple APIs to be used for entering or exiting the full screen mode in Universal apps. If we want to, we can even set the preferred launch windowing mode, which makes it easy to put the window in the best possible mode for the content of our app.

Igor Ralic

igor ralic

View Comments
Microsoft Certified Solutions Developer: Windows Store Apps in C#