WinUI3XamlPreview 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WinUI3XamlPreview --version 0.2.0                
NuGet\Install-Package WinUI3XamlPreview -Version 0.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WinUI3XamlPreview" Version="0.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WinUI3XamlPreview --version 0.2.0                
#r "nuget: WinUI3XamlPreview, 0.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WinUI3XamlPreview as a Cake Addin
#addin nuget:?package=WinUI3XamlPreview&version=0.2.0

// Install WinUI3XamlPreview as a Cake Tool
#tool nuget:?package=WinUI3XamlPreview&version=0.2.0                

WinUI 3 Xaml Preview (WinUI3XP)

nuget VS2022 CI

Image showcasing how to use WinUI 3 Xaml Preview

WinUI3 Xaml Preview allows you to see a a live preview of your UI while authoring XAML. It is fast, reliable, and comes with basic tools like scaling and size configuration.

Features:

  • Interactive preview of your XAML code (powered by XamlReader)
  • Integration with VS2022 17.9+
  • Reload via opening/saving/switching
  • Supports your own user control and custom control
  • Supports controls in dependency (i.e. libraries)

Limitation:

  • Require building the project once before use
  • Packaged apps require being deployed before use
  • Require a few lines of setup

The author does not believe in Designer so this project would stay only as a live preview. If you want a designer, fork this project and create your own.

Otherwise, contributions are welcome! 😄

Getting Started

  1. Install the VS extension. Require VS2022 17.9+

  2. On each of your WinUI 3 project that uses this feature, install the nuget

nuget install WinUI3XamlPreview
  1. If you are using C++, add <winrt/WinUI3XamlPreview.h to pch.h. C# users can go to the next step.

  2. Make changes to the start of your App.OnLaunched method accoridng to the following diff:

C++

- void App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e)
+ winrt::fire_and_forget App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e)
+ {
+     if (co_await WinUI3XamlPreview::Preview::IsXamlPreviewLaunched())
+     {
+         co_return;
+     }
      // Your code...

C#

- protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
+ protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
+ {
+     if (await WinUI3XamlPreview.Preview.IsXamlPreviewLaunched())
+     {
+         return;
+     }
      // Your code...
  1. If you are developing non-packaged app, you have finished the setup. If you are developing packaged app, make changes to your package manifest according to the following diff:
   <Applications>
     <Application>
+      <Extensions>
+        <uap5:Extension
+          Category="windows.appExecutionAlias">
+          <uap5:AppExecutionAlias>
+            <uap5:ExecutionAlias Alias="$YourTargetName-WinUI3XP.exe" />
+          </uap5:AppExecutionAlias>
+        </uap5:Extension>
+      </Extensions>
     </Application>
   </Applications>

Make sure to replace $YourTargetName with your build output name. E.g. if your build output is MyApp.exe, the correction execution alias to add is MyApp-WinUI3XP.exe.

Usage

  1. After setup, build your project again.
  2. For packaged app, deploy your app once by righting click on the project → deploy.
  3. Locate the "Toggle WinUI 3 Xaml Preview" in the "Extensions" menu at the top.
  4. Open any xaml file and click the toggle to launch preview, click it again to stop. You can also close the preview window to turn off live preview.

The preview renders according to the following triggers:

  • Opening a XAML file
  • Switching to a XAML file in the editor
  • Saving a XAML file

Technical Details

TODO

Product Compatible and additional computed target framework versions.
.NET net6.0-windows10.0.22621 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
native native is compatible. 
Universal Windows Platform uap was computed.  uap10.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.2 480 4/23/2024
0.8.1 122 4/21/2024
0.8.0 130 4/20/2024
0.7.0 119 4/20/2024
0.6.0 142 4/13/2024
0.5.0 96 4/12/2024
0.4.0 104 4/11/2024
0.3.0 101 4/10/2024
0.2.0 93 3/29/2024
0.1.0 101 3/27/2024