【发布时间】:2016-03-04 21:09:37
【问题描述】:
如何实现不隐藏任务栏、不调整大小、不设置窗口样式的自动全屏?
我尝试使用以下代码,但它不能正常工作,如下图所示。
XAML:
<Window x:Class="WPF_Test_Environment.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowState="Maximized" ResizeMode="NoResize" WindowStyle="None">
<DockPanel>
<Button DockPanel.Dock="Top" Height="50">Top</Button>
<Button DockPanel.Dock="Bottom" Height="50">Bottom</Button>
<Button DockPanel.Dock="Left" Width="50">Left</Button>
<Button DockPanel.Dock="Right" Width="50">Right</Button>
<Button Width="50" Height="50">Center</Button>
</DockPanel>
</Window>
代码隐藏:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MinHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
MinWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
}
如您所见,“底部”按钮部分位于任务栏下方,我希望它完全位于其上方。因此,理想情况下,它看起来如下图所示,但顶部没有边框:
【问题讨论】:
-
计算任务栏高度并设置窗口高度=(屏幕高度-任务栏高度)
-
为什么不只使用WindownState?。最大化状态应该为您完成所有工作。
-
@icebat - 因为我不想要顶部的“x”按钮...
-
@null1941- 谢谢,我会试试的。但是有没有更...优雅的解决方案?
标签: c# wpf fullscreen