C# Window窗体最大化时默认显示不会覆盖任务栏
所以只有通过设置窗体的大小来模拟最大化效果
Rect WinBounds = new Rect();
public void ShowWin()
{
Window win = new Window();
win.Topmost = true;
win.StateChanged += (ss, ee) =>
{
Window w = ss as Window;
if ((ss as Window).WindowState == WindowState.Maximized)
{
w.WindowState = WindowState.Normal;
if (w.ActualHeight == SystemParameters.PrimaryScreenHeight) //模拟“最大化”
{
w.Left = WinBounds.Left;
w.Top = WinBounds.Top;
w.Width = WinBounds.Width;
w.Height = WinBounds.Height;
}
else
{
WinBounds = w.RestoreBounds; //记录还原窗口的大小位置
w.Left = 0;
w.Top = 0;
w.Width = SystemParameters.PrimaryScreenWidth;
w.Height = SystemParameters.PrimaryScreenHeight;
//此时如果需要去掉边框可在此处添加下面两行
w.CanResize=ResizeMode.NoResize;
w.WindowStyle=WindowStyle.None;
}
}
};
win.Show();
}
方法可以定义在自定义类内部。