2010-05-31 83 views
2

基本上,我需要一個窗口,看起來像下面的圖片:http://screenshots.thex9.net/2010-05-31_2132.png非調整大小,邊界WPF的Windows與WindowStyle =無

(未調整大小,但仍保留了玻璃邊框)

我已經設法讓它與Windows窗體一起工作,但我需要使用WPF。爲了得到它在Windows窗體工作,我用下面的代碼:

protected override void WndProc(ref Message m) 
    { 
     if (m.Msg == 0x84 /* WM_NCHITTEST */) 
     { 
      m.Result = (IntPtr)1; 
      return; 
     } 
     base.WndProc(ref m); 
    } 

這不正是我想要它,但我不能找到一個WPF當量。我用WPF設法得到的最接近的結果是Window忽略了任何鼠標輸入。

任何幫助將非常感激:)

+0

您是否可以重新提出這個問題,因爲WPF窗口的「WindowStyle = None」設置看起來完全符合您的要求,例如,一個帶有小玻璃邊框的窗戶,尺寸可以調整,看起來就像截圖一樣。 – 2010-05-31 12:02:12

+0

我希望窗口不可調整大小,但保留玻璃邊框。我在我的問題中說得很清楚。 – danielmartinoli 2010-06-01 01:34:59

回答

1

您需要添加一個鉤子消息循環:

private void Window_Loaded(object sender, RoutedEventArgs e) 
{ 
    var interopHelper = new WindowInteropHelper(this); 
    var hwndSource = HwndSource.FromHwnd(interopHelper.Handle); 
    hwndSource.AddHook(WndProcHook); 
} 

private IntPtr WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 
{ 
    if (msg == 0x84 /* WM_NCHITTEST */) 
    { 
     handled = true; 
     return (IntPtr)1; 
    } 
} 
2

一個非常簡單的解決辦法就是設置每個窗口相等的最小和最大尺寸彼此之間以及窗口構造器中的固定編號。就像這樣:

public MainWindow() 
{ 
    InitializeComponent(); 

    this.MinWidth = this.MaxWidth = 300; 
    this.MinHeight = this.MaxHeight = 300; 
} 

這樣用戶不能改變窗口的寬度和高度。您還必須設置「WindowStyle = None」屬性才能獲得玻璃邊框。