在 Winforms 中托管 WPF 控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16901253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hosting WPF controls in Winforms
提问by WPF Learner
My Application is developed using WinForms. Is it possible to host the WPF DataGrid, Button, ListBox, ComboBoxetc in WinForms User Controls?
我的应用程序是使用 WinForms 开发的。是否有可能举办WPF DataGrid,Button,ListBox,ComboBox等中的WinForms用户控件?
回答by Federico Berasategui
Yes, it's possible using the ElementHostcontrol in Winforms and hosting WPF content inside of it.
是的,可以使用ElementHostWinforms 中的控件并在其中托管 WPF 内容。
回答by Nishant
I would not mix WinForm and WPF unless absolutely necessary. Though, Microsoft has provided the way to use WPF control in WinForm and vice-versa but it doesn't always give good result. WF and WPF renders the controls in different ways and you may face multiple issues including performance and UI flickering depending on the way they have been used.
除非绝对必要,否则我不会混合使用 WinForm 和 WPF。虽然,Microsoft 提供了在 WinForm 中使用 WPF 控件的方法,反之亦然,但它并不总是给出好的结果。WF 和 WPF 以不同的方式呈现控件,您可能会面临多个问题,包括性能和 UI 闪烁,具体取决于它们的使用方式。
If you really want to use WPF control in WF then use ElementHost control.
如果你真的想在 WF 中使用 WPF 控件,那么使用 ElementHost 控件。
ElementHost.Child = wpfControl;

