How to Use Libraries (WPF/WinForms) in .NET MAUI

Learn how to use WindowsDesktop features like WPF and WinForms in a .NET MAUI project by referencing a separate class library to overcome configuration limits.

The WindowsDesktop library is enabled by setting <UseWindowsForms>true</UseWindowsForms> and <UseWPF>true</UseWPF> in the PropertyGroup node of the project file, adding net8.0-windows to TargetFrameworks, and including conditional logic in the PropertyGroup node.
Due to unknown reasons, these settings cannot be applied directly in a MAUI project and must be configured in a separate class library, which is then referenced by the MAUI project.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net8.0;net8.0-windows</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>
    <!--MSAL will run on Windows 7 and 8 but requires to be built against Win10 to use WinRT APIs for WAM
    See https://learn.microsoft.com/dotnet/standard/analyzers/platform-compat-analyzer and
    https://github.com/dotnet/designs/blob/main/accepted/2020/platform-checks/platform-checks.md for details-->
    
    <SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
  </PropertyGroup>
</Project>
Built with Hugo
Theme Stack designed by Jimmy