Windows 10 上的空白 WPF 子窗口

Mar*_*Mar 6 windows wpf windows-10

我从 Windows 8.1(64 位)升级了 Windows 10。在 WPF 应用程序(由我或其他人开发,如屏幕截图上的todotxt.net)中,子窗口大部分时间都是空白的。

如果我将鼠标移到控件上,它们中的一些会出现(我猜是因为它们处理WM_MOUSEHOVER消息以重新绘制自己)。有时窗口没问题(大约 10-20% 的启动)。我通过隐藏和显示控件暂时解决了这个问题(请阅读下文)。

在 Hyper-V 上全新安装 Windows 10 不会重现该错误。

有没有人遇到过类似的问题?你是怎么解决的?

这是它的外观(空白子窗口):

1 个选项-空白

鼠标移动后:

2个选项-mousemove

我的解决方案

我无法在 Internet 上找到任何其他解决方案。如果您找到任何其他解决方案,请告诉我。

首先,简单的重绘(通过InvalidateVisual())并没有解决问题。

我决定处理ContentRendered事件并隐藏然后显示所有控件。这个技巧有效,但它“闻起来”。

mainGrid下面的代码中,是我的子窗口最顶层 Grid 的名称:

XAML:

<Window x:Class="MyApp.About"
    .........
    ContentRendered="Window_ContentRendered" 
    ...... >
    <Grid x:Name="mainGrid" ... >
Run Code Online (Sandbox Code Playgroud)

CS:

private void Window_ContentRendered(object sender, EventArgs e)
{
    InvalidateVisual(); // Just in case
    var childCount = VisualTreeHelper.GetChildrenCount(mainGrid);

    for (int i = 0; i < childCount; ++i)
    {
        var child = VisualTreeHelper.GetChild(mainGrid, i) as UIElement;

        if (child != null)
        {
            child.Visibility = Visibility.Hidden;
            child.Visibility = Visibility.Visible;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bil*_*ary 5

根据我的观察,这仅是 Windows 10 上的 Intel GPU 驱动程序问题(Windows 8 很好)。我们有一个拥有数千名用户的 WPF 桌面应用程序,它在 Windows 7、8、8.1 中运行良好,但当安装在 Windows 10 中时,某些 Windows 10 运行良好,但有些将出现该线程所解释的内容。

要解决此问题,最简单的方法是更新有问题机器的 Intel GPU 驱动程序。如果您拼命地发现即使您已经运行了最新的 Windows 更新也无济于事并且问题仍然存在,请尝试通过以下方式手动更新驱动程序:

  1. 在“设备管理器”中,右键单击图形卡并选择“更新驱动程序”。
  2. 这样,Windows 10 将尝试查找有时在 Windows 更新中不可用的最新驱动程序。
  3. 如果设备管理器告诉您的驱动程序已经是最新版本,最后的方法是在此处查找驱动程序:https : //downloadcenter.intel.com/

对于某些运行新 CPU/GPU (Atom X7) 的机器,例如 Microsoft Surface 3(不是 Surface pro),更新驱动程序似乎还不可能,我仍在为此类机器寻找解决方案。

在其他情况下,我的大部分 Intel HD GPU 在更新到驱动程序版本 10.18.15.4278 后都解决了这个问题

注 1:到目前为止,我还没有在其他 GPU 上看到这个问题,比如 Nvidia 或 ATI。注 2:总的来说,我想说,除了最新的 Intel Atom X5/X7,大多数其他 Intel HD Graphic 应该能够执行驱动程序更新并解决这个问题。


bre*_*eto 4

我现在已经更新了我的视频驱动程序,这似乎已经解决了问题。

Windows 现在可以正确显示,无需下面列出的附加代码。:)

自从从 8.1 升级到 Windows 10 后,我遇到了同样的问题。我改变了窗口加载方法:

        WindowState = WindowState.Maximized;
        WindowState = WindowState.Normal;
Run Code Online (Sandbox Code Playgroud)

这似乎“重绘”窗口元素以便它们显示。我已经对此进行了多次测试,每次窗口在从最大化状态立即恢复后都会正确显示。我没有在xaml中设置窗口状态。

(另一个“修复”是设置尺寸绑定,例如按特定名称为该类型的所有单个对象设置宽度)。