修复WPF对话窗口留下的显示垃圾? [英] Fix display garbage left by WPF dialog window?

查看:129
本文介绍了修复WPF对话窗口留下的显示垃圾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序中,我有WPF窗口可以打开其他WPF对话窗口,我做如下:

  PickForEveryone PickForEveryoneWindow = new PickForEveryone(sSelRecipe,selMRM.sDay,selMRM.MealTypeID); 
PickForEveryoneWindow.Owner = this;
PickForEveryoneWindow.ShowDialog();

其中PickForEveryone定义为:

  public partial class PickForEveryone:Window 

 < Window x:Class =PFWb0.PickForEveryone
xmlns =http://schemas.microsoft.com/winfx/ 2006 / xaml / presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
xmlns:dg =http://schemas.microsoft.com/ wpf / 2008 / toolkit
ShowInTaskbar =False
Title =Pick Recipe For AllHeight =536Width =441
WindowStartupLocation =CenterOwner>

并包含一个带有DataGrid的网格和几个按钮和复选框。



在我的开发计算机上工作正常。但是,当对话窗口关闭时,我的客户端会不断地看到对话框窗口将其显示的一部分留在父窗口顶部的可视化垃圾。也就是说,当ShowDialog()返回时,窗口中只有一些窗口未被取消。



我尝试添加this.InvalidateVisual();下面的代码,但它没有解决问题。



我也看到一个建议(为另一种WPF显示问题)调用OnRender()到强制重画,但OnRender需要一个DrawingContext类型的参数,我不知道如何获取。



所以,我问是否有人知道如何修复显示问题在第一位,或如何通过获取WPF重新绘制窗口从中恢复。



更新:正如在下面的建议答案的评论中看到的,我仍然没有解决方案可以在我的客户端的计算机上工作,而我的解决办法(让窗口相互躲避)已经不够了。唯一有效的是最大限度地减少污染的底层窗口。

解决方案

我在具体的计算机上有类似的问题一个ATOM N270处理器。
这个问题需要连接到图形硬件加速。



要停用加速功能,只需将其添加到注册表(这将会停用所有硬件加速WPF应用程序):

  HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration 

我必须创建 Avalon.Graphics 文件夹。



DisableHWAcceleration 是一个 DWORD ,必须设置为 1



这解决了我的问题,如果我重新启动加速,问题回来了。



希望这有帮助。



参考文献:




In my WPF app, I have WPF windows that can open other WPF dialog windows, which I do as follows:

PickForEveryone PickForEveryoneWindow = new PickForEveryone(sSelRecipe, selMRM.sDay, selMRM.MealTypeID);
PickForEveryoneWindow.Owner = this;
PickForEveryoneWindow.ShowDialog();

Where PickForEveryone is defined as:

public partial class PickForEveryone : Window

and

<Window x:Class="PFWb0.PickForEveryone"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
 ShowInTaskbar="False"
 Title="Pick Recipe For All" Height="536" Width="441" 
 WindowStartupLocation="CenterOwner">

And contains a Grid with a DataGrid and a few buttons and check boxes.

Which works fine on my development computers. However, my client keeps seeing the dialog windows leave part of their display as visual litter on top of the parent window when the dialog window closes. That is, only some of the window undraws when ShowDialog() returns.

I tried adding this.InvalidateVisual(); below the above code, but it didn't solve the problem.

I also saw a suggestion here (for another kind of WPF display problem) to call OnRender() to force a redraw, but OnRender requires a parameter of type DrawingContext, which I don't know how to get.

So, I am asking if anyone knows how to either fix the display problem in the first place, or how to recover from it by getting WPF to redraw a window.

Update: As seen in comments to suggested answers below, I still have no solution that works on my client's computers, and my workaround (of having the windows dodge each other) is no longer enough. The only thing that works is to minimize and maximize the polluted underlying window.

解决方案

I had a similar problem on a specific computer with an ATOM N270 processor. The problem seamed to be linked to the graphic hardware acceleration.

To deactivate the accelaration, just add this to the registery (this will deactivate hardware acceleration for all WPF applications) :

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration

I had to create the Avalon.Graphics folder.

DisableHWAcceleration is a DWORD that has to be set to 1.

This had solve my problem, if I reactivate the acceleration, the problem come back.

Hope this helps.

References :

这篇关于修复WPF对话窗口留下的显示垃圾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆