我有一個multimonitor系統的問題,並最大化我的無邊框WPF C#.NET 4.0窗口。一臺顯示器是1680x1050(主要),第二個是1920x1080(次要)。當我在主屏幕上最大化我的窗口時 - 即使切換這兩個窗口的順序也沒有問題。但每次我試圖在輔助屏幕上最大化它時,它都會被切斷到主監視器的大小。我發現窗口大小是合適的,但這不起作用。WPF無邊界窗口只是最大化主屏幕大小
獲取顯示器的大小:
private System.Windows.Forms.Screen GetCurrentScreen()
{
System.Drawing.Point centerPoint = new System.Drawing.Point((int)(Left + Width/2), (int)(Top + Height/2));
foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens)
{
if (s.Bounds.Contains(centerPoint))
{
return s;
}
}
return null;
}
最大化:
private void Maximize
{
if (this.WindowState == WindowState.Normal)
{
var scr = GetCurrentScreen();
//this.MaxHeight = scr.WorkingArea.Height;
//this.MaxWidth = scr.WorkingArea.Width;
if (scr != null)
{
if (scr.Primary)
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
else
{
this.MaxHeight = double.PositiveInfinity; //even ridiculous values don't work
this.MaxWidth = double.PositiveInfinity;
this.Height = scr.WorkingArea.Height; // correct values of 2nd screen
this.Width = scr.WorkingArea.Width;
}
}
else
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
this.WindowState = WindowState.Maximized;
}
我得到的是: http://imgur.com/ZYzVV9Q,yf7lSfY#1
我想要什麼: http://imgur.com/ZYzVV9Q,yf7lSfY#0
比KS
你有tr ied只需使用'this.WindowState = WindowState.Maximized;'*代替*所有手動代碼來調整'Window'的大小? – Sheridan
是的,我試過了,但還是一樣。 –
有可能你的代碼導致了這個問題,因爲我不能在我的兩個屏幕上覆制它們......它們的大小都是一樣的,但是如果我改變了一個分辨率,那麼應用程序仍然能夠正確地最大化。如果你啓動一個新的WPF應用程序,並且只需在窗口聲明中添加WindowState =「Maximized」',你是否仍然存在相同的問題? – Sheridan