Create highly performant UI with WinUi2 (Uwp) and enjoy the freedom of Win32!
You don't need any interop code for the .GetForCurrentView() methods.
- The library does currently not support any Uwp-Frame related apis
- Therefore not frame customization
- Creating a new window is only possible with the library apis
- Pickers still need
IInitializeWithWindow(See #11)
- Create new Uwp project (UI-Project)
- Add
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>in to the project file - Add reference to this library
- Create new
netcoreapp3.1WinExeproject (Host-Project) - Add reference to
Microsoft.Toolkit.Win32.UI.SDK - Add reference to Uwp project
- Add
TargetPlatformVersionandAssetTargetFallbackto the project file - Redirect main method to the Uwp main method (See below)
This is needed for the management of all the dependency and runtime stuff.
Should contain no logic.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <Platforms>x86;x64</Platforms> <AssetTargetFallback>uap10.0.19041</AssetTargetFallback> <TargetPlatformVersion>10.0.19041</TargetPlatformVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Toolkit.Win32.UI.SDK" Version="6.1.2" /> </ItemGroup> <ItemGroup> <ProjectReference Include="<PATH_TO_UWP_PROJECT>" /> </ItemGroup> </Project>
public class Program { [STAThread] public static void Main(string[] args) { NAMESPACE.Program.Main(args); } }
Should contain all logic.
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <EnableTypeInfoReflection>false</EnableTypeInfoReflection> </PropertyGroup> ... </Project>
public class Program { [STAThread] public static void Main(string[] args) { FullTrustApplication.Start((_) => new App()); } }
var view = FullTrustApplication.CreateNewView(); _ = view.CoreWindow.Dispatcher.RunIdleAsync((x) => { Window.Current.Content = new MainPage(); Window.Current.Activate(); });