The reason I'm asking is because I want to use certain classes from Winforms in a WPF application.
CodePudding user response:
Yes, it's OK and there are valid scenarios which you may want to add both frameworks. It's already mentioned in the documentations, you can add both, if necessary:
- Add a UI framework property (or both, if necessary):
- Set UseWPF to true to import and use WPF.
- Set UseWindowsForms to true to import and use WinForms.
And also the example shows the same:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<!-- and/or -->
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
CodePudding user response:
Yes, this works just fine. You can have an application use both WinForms and WPF, even intermixed. There are even controls to host a WPF control inside a Winforms window and WinForms controls inside a WPF window (see e.g. here).
There are a some limits when doing this extensively (WPF hosts WinForms control, hosts WPF control hosts... etc may not work) but I've been working on a GUI that has everything intermixed (for legacy reasons) and it is generally working great.