Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF fullscreen mode

Tags:

c#

.net

wpf

I am creating an WPF application which has following XAML structure.

<Window>
   <ScrollViewer>
       <Grid>
       ...
       ...
       ...
       </Grid>
   </ScrollViewer>
</Window>

I want to run application on fullscreen on the press of 'F' button and for that i tried following code.

private void window1_KeyUp(object sender, KeyEventArgs e)
{

  if(e.Key == Key.F)
  {
       if(!isFullScreen)
       {
            height = mePlayer.Height;
            width = mePlayer.Width;
            mePlayer.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
            mePlayer.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Background = new SolidColorBrush(Colors.Black);
            this.WindowStyle = WindowStyle.None;
            this.WindowState = WindowState.Maximized;
            isFullScreen = !isFullScreen;
       }
       else
       {
            mePlayer.Height = height;
            mePlayer.Width = width;
            this.Background = new SolidColorBrush(Colors.White);
            this.WindowStyle = WindowStyle.SingleBorderWindow;
            isFullScreen = !isFullScreen;
        }
   }
 }

I am Facing following two problems.

  1. When i press F key for full screen, window goes to full screen mode but task bar is still visible
  2. In full screen mode scroll bar becomes visible.

I don't know why this is happening. I think scroll bar becomes visible because of the taskbar. Any help would greatly appreciated.

Here is the screen shot of what is happening. enter image description here

like image 744
Bhavesh Jadav Avatar asked Jun 19 '15 16:06

Bhavesh Jadav


People also ask

How to open WPF window in fullscreen on a specific monitor?

If you have a Multi Monitor setup in Windows and you want to open a WPF window in fullscreen in a specific monitor you have no native option , but it is quite simple to obtain such functionality. First of all you need to reference Winform assembly, because you need winform code to identify information for screens setup in the current system.

How to enable full screen mode in AutoCAD?

Enable full screen mode. You can choose to hide all tool windows and view only document windows by enabling Full Screen mode. Press Alt+Shift+Enter to enter or exit Full Screen mode. Issue the command View.Fullscreen in the Command window.

How do I view full screen in Visual Studio Code?

You can choose to hide all tool windows and view only document windows by enabling Full Screen mode. Press Alt + Shift + Enter to enter or exit Full Screen mode. Issue the command View.Fullscreen in the Command window. In Virtual Space mode, spaces are inserted at the end of each line of code.

How do I make my application run in full screen independently?

I'd like my application to run in full screen independently from its dimensions. What is the best practice to accomplish this task? Just set the WindowState to Maximized, and the WindowStyle to None. Also setting the Window as topmost will make sure no other Window shows up over your window. @YashGadhiya Which you should never do.


Video Answer


1 Answers

I'm not sure why you're doing all the extra stuff but doing this seems to be sufficient and working fine:

private void window1_KeyUp(object sender, KeyEventArgs e)
{

  if(e.Key == Key.F)
  {
       if(!isFullScreen)
       {
            this.WindowStyle = WindowStyle.None;
            this.WindowState = WindowState.Maximized;
            this.SC.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
            this.SC.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            isFullScreen = !isFullScreen;
       }
       else
       {
            this.WindowStyle = WindowStyle.SingleBorderWindow;
            this.WindowState = WindowState.Normal;
            this.SC.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            this.SC.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            isFullScreen = !isFullScreen;
        }
   }
 }

SC is my ScrollViewer.

like image 61
Maxime Tremblay-Savard Avatar answered Oct 22 '22 17:10

Maxime Tremblay-Savard