问题描述
我在用 WPF 和 C# 创建的应用程序中有一个窗口.我已经设置了 MaxHeight=200、MaxWidth=500 和 StartupLocation=CenterScreen.但是最大化这个窗口使它位于屏幕的左上区域,即:不再在中心!即使我在最大化的条件下在 Window_StateChanged 事件中设置了 Left=200 和 Top=200,最大化的窗口总是在左上方.
I have a window in an application created with WPF and C#. I have set MaxHeight=200, MaxWidth=500 and StartupLocation=CenterScreen.However maximizing this window makes it positioned on the left upper region of the screen i.e: not in the center any more! The maximized window is always on the left upper part even though I set Left=200 and Top=200 in the Window_StateChanged event on the condition of maximizing.
private void Window_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
// Left = System.Windows.SystemParameters.WorkArea.Width - Width;
Left = 200;
// Top = System.Windows.SystemParameters.WorkArea.Height - Height;
Top = 200;
}
}
我应该怎么做才能确保最大化的窗口位于中心?非常感谢.
What should I do to make sure the maximized windows is positioned in the center?Thanks very much in advance.
推荐答案
当您在 Window_StateChanged 中检测到 Maximized 时,将其设置回 Normal.看看这个:在 wpf 窗口中禁用最大化容量
When in Window_StateChanged you detect Maximized set it back to Normal. Take a look at this: disable maximize capacity in a wpf window
这篇关于C# WPF 最大化窗口的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!