在我的应用程序中,在菜单上单击我们将启动一个窗口。加载时,窗口会变黑几秒钟,然后出现控件。我已附上图片以供参考。请帮帮我 。 。加载窗口时出现黑色空白窗口WPF
回答
您是否在项目中导入和使用WindowChrome类(System.Windows.Shell)?当我将这个类导入到我的项目中时,发生了这个问题。
不,我们在我们的项目中没有使用WindowChrome类,但我们正在导入[DllImport(“user32.dll”)] –
set AllowsTransparency =“True”。这可能会解决您的问题。 –
我尝试使用上面的代码,仍然没有按预期工作。 –
你应该阅读:
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();
}
}
除了设置背景刷之外,您能否提出其他解决方案?因为我尝试了以上所有建议的解决方案,但没有为我工作...... –
- 1. CreateProcessAsUser创建空白/黑色窗口
- 2. WPF窗口显示空白
- 3. wpf窗口全黑
- 4. 乌龟窗口出现空白
- 5. TinyMCE弹出窗口空白
- 6. JavaScript弹出窗口空白
- 7. 黑空窗口Kivy
- 8. WPF窗口的黑色背景
- 9. WPF:黑色区域在窗口右侧
- 10. 在WPF设计器的窗口上方出现白色边框
- 11. GLUT:空白窗口
- 12. IronPython WPF加载新窗口
- 13. WPF - window.ShowDialog窗口内。加载
- 14. WPF窗口预加载
- 15. WPF:从XAML加载窗口
- 16. 窗口加载和WPF
- 17. 验证WPF关闭窗口在窗口加载时失败
- 18. EmguCV Canny黑色窗口
- 19. CollectionView窗口保持黑色
- 20. WPF BackgroundWorker主窗口加载时
- 21. 在pygame中打开一个空白的黑色窗口
- 22. 意外的零窗口(空白的黑色屏幕)
- 23. Pygame窗口显示空白的黑色屏幕
- 24. 每次调整WPF窗口大小时,为什么会出现黑色延迟?
- 25. WPF弹出窗口
- 26. 从Android白色窗口淡入/淡出
- 27. 启动Chrome Packaged应用程序时出现空白窗口
- 28. 程序运行时出现空白窗口?
- 29. 空白窗口的JavaFX
- 30. 带TTSplitViewController的空白窗口
你的问题缺少所需行为的描述。 – grek40