Search code examples
c#wpfwinformsvisual-studio-2017

How can I make a WPF window look like a Winforms window?


I am in the process of transforming a UI from winforms to WPF. Previously, selecting a tree view would just show a different winform page based on the tree view item selected. Now, I have inserted a WPF DockPanel and every time a treeview item is selected a different winformhost element gets added to the WPF DockPanel.

When I was running on winforms my UI looked like this: enter image description here

Now when I run my application with my WPF DockPanel with the WinformHostElements my UI looks like: enter image description here

Is there a way for me to apply a style to the WPF DockPanel that looks similar to the winform controls?

(This is only while I finish converting all winform elements to WPF elements.)


Solution

  • Transforming between WinForms and WPF is far from easy. The issue is that XAML and WPF/UWP were designed with the MVVM pattern in mind. While you can use other Design patterns, doing so misses about 90% of the XAMLs power and runs into issues at every other turn. I wrote a intro into MVVM a few years back: https://social.msdn.microsoft.com/Forums/vstudio/en-US/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2/lets-talk-about-mvvm?forum=wpf

    What you have right now might be suiteable classes for the Model part of MVVM. But maybe converions is unessesary: For backwards compatibility (and to fill some gaps), WPF does have a way to host WindowsForm era elements: https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf