2013-10-22 127 views
1

我有一個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

+0

你有tr ied只需使用'this.WindowState = WindowState.Maximized;'*代替*所有手動代碼來調整'Window'的大小? – Sheridan

+0

是的,我試過了,但還是一樣。 –

+0

有可能你的代碼導致了這個問題,因爲我不能在我的兩個屏幕上覆制它們......它們的大小都是一樣的,但是如果我改變了一個分辨率,那麼應用程序仍然能夠正確地最大化。如果你啓動一個新的WPF應用程序,並且只需在窗口聲明中添加WindowState =「Maximized」',你是否仍然存在相同的問題? – Sheridan

回答

1

有一種可能性是你的代碼導致了這個問題,因爲我無法在我的兩個屏幕上覆制它們......它們都是相同的大小,但是如果我改變一個分辨率,應用程序仍然正確地最大化。如果你開始一個新的WPF應用程序,只是添加

WindowState = "Maximized" 

到窗口申報,你仍然有同樣的問題?

+0

感謝您的幫助。我在其他地方操縱了我窗戶的大小,情況就是這樣。但沒有你的提示,我不會找到它並修復它。 –

+0

不客氣......這很容易和經常完成。 – Sheridan

2

這爲我工作我最後一次最大化我的輔助屏幕上的窗口:

Screen sTwo = Screen.AllScreens[1]; 
this.Top = sTwo.Bounds.Top; 
this.Left = sTwo.Bounds.Left; 
this.Width = sTwo.Bounds.Width; 
this.Height = sTwo.Bounds.Height; 

確保你添加引用

using System.Windows.Forms; 

並設置

AllowsTransparency="True" 

在你的* .xaml

相關問題