2017-01-04 81 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

除了设置背景刷之外,您能否提出其他解决方案?因为我尝试了以上所有建议的解决方案,但没有为我工作...... –