How to implement a full-screen button that honors light and dark modes

BitSmithy 2,206 Reputation points
2024-10-23T14:59:05.72+00:00

Hello,

I want to implement a Full-Screen button. I found in net any solutions, but they doesnt honors Dark Mode.

The button must be placed on app upper belt near minimize/maximize/close window buttons.

Could anyone tell how to implement full-screen button that honors Light and Dark modes in recomended way?

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2024-10-24T07:04:00.9933333+00:00

    Hello @BitSmithy ,

    Welcome to Microsoft Q&A!

    Here is an example of using a custom title bar.

    It is recommended to use the system's button to exit the full screen mode, the button in this sample will be hidden when full screen.

     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="32"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
         <Grid x:Name="AppTitleBar" Background="Transparent">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
                 <ColumnDefinition/>
                 <ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
             </Grid.ColumnDefinitions>
         </Grid>
         <StackPanel Orientation="Horizontal"
                     VerticalAlignment="Center" 
                     HorizontalAlignment="Right" 
                     Height="32"
                     Grid.Column="0">
             <Button x:Name="fullScreenbtn" Content="FullScreen" Click="Button_Click" Width="90"/>
             <Rectangle Width="140" Height="32"/>
         </StackPanel>
     </Grid>
    
    
    public MainPage()
    {
        this.InitializeComponent();
        var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
        coreTitleBar.ExtendViewIntoTitleBar = true;
        this.SizeChanged += MainPage_SizeChanged;
        // Set XAML element as a drag region.
        Window.Current.SetTitleBar(AppTitleBar);
    }
    private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        var view = ApplicationView.GetForCurrentView();
        if (view.IsFullScreenMode)
        {
            fullScreenbtn.Visibility = Visibility.Collapsed;
        }
        else
        {
            fullScreenbtn.Visibility = Visibility.Visible;
        }
    }
    private void Button_Click(object sender, RoutedEventArgs e)
    {
             
        var view = ApplicationView.GetForCurrentView();
        if (view.IsFullScreenMode)
        {
            view.ExitFullScreenMode();
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            fullScreenbtn.Visibility = Visibility.Visible;
                  
        }
        else
        {
            if (view.TryEnterFullScreenMode())
            {
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
                fullScreenbtn.Visibility= Visibility.Collapsed;               
            }
        }
    }
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.