I've spent some time working on WinForm user and custom controls. However, in the back of my mind are the increasingly loud voices saying that WinForm technology is obsolete, and that WPF is the future on the desktop.
I've only looked superficially at WPF. Can anyone comment about if WinForm user controls can be used at all on WPF, and how different WinForm user controls are from WPF user controls?
Most of the controls I'm working on do some type of owner-draw as opposed to child controls being dropped onto the control. I'm just wondering how much of this code will be reusable under WPF.
It is certainly possible to use WinForms controls in a WPF application using the WindowsFormHost
control. As usual, there are a few caveats. In particular, the two control types don't overlap well.
However, doing so seems that it would prevent you from taking advantage of many (if not nearly all) of the benefits of switching to WPF in the first place. If you have a large code base that's working for you, I'm not sure why you feel you need to migrate. There will always be something newer that comes along. The real battle is figuring out whether it's really better, at least for your particular situation.
Mandatory disclaimer: I'm far from an expert on WPF and apparently quite a bit less jaded on WinForms than many developers are. So perhaps my advice should be taken with a grain of salt, but I think it's worth considering nevertheless.
Your controls will be reusable (through WindowsFormHost
, as Cody suggested). However, I'd not bank on being able to port your code across to WPF. The fundamental programming model is quite different (WPF relies heavily on data binding and thus benefits from very different code-behind), as is the rendering model (WPF doesn't use GDI+). The best way to approach most controls in WPF is to use the built-in templating; other than custom layout panels (which isn't really "drawing"), I've found nothing so far that requires custom draw methods in controls.
It'd certainly be a waste to create a WPF application just to host your WinForms controls. WPF may (or may not!) be "the future" but that doesn't mean you should throw away what you've got on a whim.
You say you've only looked superficially. If you think it might be worth investment, why not do an R&D project to prove how the integration might work on a small part of the system?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With