2017-01-04 82 views

回答

0

您是否在項目中導入和使用WindowChrome類(System.Windows.Shell)?當我將這個類導入到我的項目中時,發生了這個問題。

+0

不,我們在我們的項目中沒有使用WindowChrome類,但我們正在導入[DllImport(「user32.dll」)] –

+0

set AllowsTransparency =「True」。這可能會解決您的問題。 –

+0

我嘗試使用上面的代碼,仍然沒有按預期工作。 –

0

你應該閱讀:

How to fix the WPF form resize - controls lagging behind and black background?

你可以改變黑位顯示通過調用SetClassLong方法,通過@@ ghord所建議的顏色:

public static class WindowExtensions 
{ 
    private const int GCL_HBRBACKGROUND = -10; 
    private const int COLOR_WINDOW = 5; 

    public static void SetClassLong(this Window window) 
    { 
     //change the background colour of the window to "hide" possible black rendering artifacts 
     IntPtr handle = new WindowInteropHelper(window).EnsureHandle(); 
     if (handle != IntPtr.Zero) 
      SetClassLong(handle, GCL_HBRBACKGROUND, SafeNativeMethods.GetSysColorBrush(COLOR_WINDOW)); 
    } 

    private static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) 
    { 
     if (IntPtr.Size > 4) 
      return SafeNativeMethods.SetClassLongPtr64(hWnd, nIndex, dwNewLong); 
     else 
      return new IntPtr(SafeNativeMethods.SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32()))); 
    } 
} 

public partial class MainWindow : Window, IViewFor<MainWindowViewModel> 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    protected override void OnSourceInitialized(EventArgs e) 
    { 
     base.OnSourceInitialized(e); 
     //change the background colour of the window to "hide" possible black rendering artifacts 
     this.SetClassLong(); 
    } 
} 
+0

除了設置背景刷之外,您能否提出其他解決方案?因爲我嘗試了以上所有建議的解決方案,但沒有爲我工作...... –