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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With