在WinForms MDI应用程序中托管WPF用户控件时,如何避免出现视觉伪影? [英] How to avoid visual artifacts when hosting WPF user controls within a WinForms MDI app?
问题描述
当在WinForms MDI应用程序中托管WPF用户控件时,当您有多个相互重叠的表单时会出现图形问题,从而导致非常明显的视觉瑕疵.在将一个子窗体拖到另一个也承载WPF内容的子窗体之后,或者通过在拖动它时,主MDI父对象允许子窗体的边缘被剪切,这些伪像在大多数情况下是可见的.子窗体的拖放完成后,工件通常会停留在周围,但是我发现将焦点设置到其他应用程序的窗口上,然后重新聚焦到我的应用程序窗口上,重新绘制它,一切都很好,直到子窗体表单再次移动.请查看下面显示问题的图像.
When hosting WPF user controls within a WinForms MDI app there is a drawing issue when you have multiple forms that overlap each other that causes very distinct visual artifacts. These artifacts are mostly visible after dragging one child form over another one that also hosts WPF content or by allowing the edges of the child form to be clipped by the main MDI parent when dragging it around. After the drag and drop of the child form is completed the artifacts stay around generally but I've found that setting focus to a different application's window and then refocusing back on to my application window that it is redrawn and all is good again until the child forms are moved once again. Please see the image below which demonstrates the problem.
Microsoft的那些人坚持认为WinForms MDI已经是MDI的足够解决方案,并且不需要在WPF中进行重新发明,尽管我发现很难相信他们由于明显的缺点而尝试以这种方式创建WPF应用程序.
Those at Microsoft insist that the WinForms MDI is already a sufficient solution for MDI and doesn't need reinventing in WPF although I find it hard to believe they tried creating a WPF app this way because of the obvious shortcomings.
更新:我遗漏的一些其他注意事项是,如果我在不设置MdiParent的情况下创建这些表单,则会将它们创建为常规表单,并且不会发生此问题.对于WinForms MDI方案,此问题似乎是唯一的.另外,我目前正在Windows 7 Enterprise上运行,我知道在Windows XP上结果可能会完全不同,但是我无法对其进行测试.
UPDATE: A few extra notes that I left out is that if I create these Forms without setting the MdiParent they are created as regular forms and this issue doesn't happen. This issue seems unique to the WinForms MDI scenario. Also I've currently running on Windows 7 Enterprise and I'm aware the results may be quite different on Windows XP but I haven't been able to test this.
更新:我发现了一些我认为应该分享的与此问题相关的其他资源.
UPDATE: I've found a few other related resources on this issue that I thought I should share.