WinForm and WPF User Controls

I spent some time working with user and user controls in WinForm. Nevertheless, in the depths of my mind, voices are heard louder, saying that WinForm technology is outdated, and WPF is the future on the desktop.

I just looked outwardly at WPF. Can anyone comment on whether WinForm user controls can be used at all in WPF and how various WinForm user controls are WPF controls?

Most of the controls that I'm working on do some type of drawing for the owner, as opposed to child controls that are deleted on the control. I'm just wondering how much of this code will be reused in WPF.

+4
source share
2 answers

Your controls will be reused (via WindowsFormHost , as Cody suggested). However, I am not going to pass my code to WPF. The fundamental programming model is completely different (WPF is heavily dependent on data binding and therefore benefits from very different code), as well as the rendering model (WPF does not use GDI +). The best way to get closer to most controls in WPF is to use built-in templates; besides custom layout panels (which are not really β€œdrawings”), I have not found anything so far, which requires special drawing methods in the controls.

To create a WPF application just to host WinForms controls would be useless. WPF may (or may not!) Be a "future", but that does not mean that you should throw away what you have on a whim.

You say that you looked only superficially. If you think this might be worth the investment, why not make an R&D project to prove how integration can work on a small part of the system?

+3
source

Of course, use WinForms controls in a WPF application using WindowsFormHost . As usual, there are a few caveats. In particular, the two types of controls do not overlap well.

However, it seems that this will prevent you from taking advantage of the many (if not almost all) benefits of switching to WPF in the first place. If you have a large code base that works for you, I'm not sure why you feel that you need to migrate. There will always be something new that will be. In a real battle, it turns out whether this is really better, at least for your specific situation.

Mandatory disclaimer: I am far from an expert on WPF and, apparently, in WinForms, it seems to be slightly smaller than many developers. Therefore, perhaps my advice should be taken with salt, but I think it's worth it to think though.

+5
source

Source: https://habr.com/ru/post/1339318/


All Articles