我正在创建一个具有以下XAML结构的WPF应用程序。
<Window>
<ScrollViewer>
<Grid>
...
...
...
</Grid>
</ScrollViewer>
</Window>
我想按下'F'按钮全屏运行应用程序,为此我尝试了下面的代码。
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;
}
}
}
我正面临两个问题。
我不知道为什么会这样。我认为由于任务栏,滚动条变得可见。任何帮助都会非常感激。
以下是正在发生的事情的屏幕截图。
答案 0 :(得分:2)
我不确定你为什么要做所有额外的事情,但这样做似乎已经足够并且工作正常:
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是我的ScrollViewer。