Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

.net - Using a custom WPF control in WinForms

I'm going to have to build a custom control for a WinForms application. But in the near future that same control will have to be used in a WPF application.

I've already written all the logic in a controller class which I can use for both WinForms and WPF (I will only have some databinding to do and that's it), but of course it would be easier to develop and maintain the control only once.

So can I build the control in WPF and then put them on a WinForms form? My projects currently have 3.0 as their target framework.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can!

In WinForms use ElementHost and add you WPF control inside (Best practice here is to create a WPF User Control and add you controls into the user control)

And in WPF, if you want to use a WinForms user control, use the WindowsFormsHost


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...