问题描述
我有一个WinForms控件,其中有一个 TableLayoutPanel
,其中包含多个 ElementHosts
,每个 ElementHost
包含一个WPF控件./p>
一切正常,除非控件的大小大于window且 ScrollBar
在那里;当我向下滚动时,控件变得失真,像这样-
最大化窗口或调整窗口大小时,控件会正确渲染(减小尺寸以使控件移出可见区域,然后再次增大尺寸以将其带回到可见区域)
在同一窗口中的WinForms控件(仅WPF窗口)不会发生这种情况;知道为什么会这样吗,对此有什么解决办法?
this.Loaded + =委托{var source = PresentationSource.FromVisual(this);var hwndTarget = source.CompositionTarget作为HwndTarget;如果(hwndTarget!= null){hwndTarget.RenderMode = RenderMode.SoftwareOnly;}};
尝试在要托管的wpf控件中使用它.这是Win窗体中托管的wpf控件的一个已知渲染问题.将渲染模式更改为仅软件即可解决问题.
I am having a WinForms control, inside that I have a TableLayoutPanel
which holds multiple ElementHosts
and each ElementHost
contains a WPF control.
Everything works fine except when the size of controls is bigger then window and ScrollBar
is there; when I scroll down, the controls get rendered distorted, like this -
On maximizing the window or re-sizing it, controls render properly(reducing the size such that controls go out of visible area and then increase the size again to bring them back in visible area)
This doesn't happen with WinForms control in the same window just the WPF ones; any idea why this is happening and any solution for this?
this.Loaded += delegate
{
var source = PresentationSource.FromVisual(this);
var hwndTarget = source.CompositionTarget as HwndTarget;
if (hwndTarget != null)
{
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}
};
Try using that in the wpf control you are hosting. This is a known rendering issue of the the wpf controls that are hosted in win forms. Changing the rendering mode to software only will solve the problem.
这篇关于ElementHost中WPF控件的呈现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!