Bhavesh Jadav
Bhavesh Jadav

Reputation: 705

WPF fullscreen mode

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

Upvotes: 8

Views: 1554

Answers (1)

Maxime Tremblay-Savard
Maxime Tremblay-Savard

Reputation: 967

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.

Upvotes: 2

Related Questions