gpt4 book ai didi

c# - WPF全屏模式

转载 作者:太空狗 更新时间:2023-10-29 19:45:13 24 4
gpt4 key购买 nike

我正在创建一个具有以下 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;
}
}
}

我面临以下两个问题。

  1. 当我按 F 键全屏时,窗口进入全屏模式但任务栏仍然可见
  2. 在全屏模式下滚动条可见。

我不知道为什么会这样。我认为滚动条因为任务栏而变得可见。任何帮助将不胜感激。

这是正在发生的事情的屏幕截图。 enter image description here

最佳答案

我不确定你为什么要做所有额外的事情,但这样做似乎就足够了并且工作正常:

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。

关于c# - WPF全屏模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30942899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com