Introduction |
Moving Win2D onto WinUI3/Project Reunion is a work in progress. Some features are not supported, and some of the Documentation still points to old WinUI2 concepts and classes.
Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to WinUI3 app developers. It utilizes the power of Direct2D, and integrates seamlessly with XAML.
Where to get it:
How to use it:
More info:
Getting Started with Project Reunion:
Add the Win2D NuGet package:
Add a CanvasControl to your XAML page:
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
<Grid> <canvas:CanvasControl Draw="CanvasControl_Draw" ClearColor="CornflowerBlue"/> </Grid>
Then add some Win2D drawing code.
using Microsoft.UI; using Microsoft.UI.Xaml.Controls; using Microsoft.Graphics.Canvas.UI.Xaml; public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) { args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.Black, 3); args.DrawingSession.DrawText("Hello, world!", 100, 100, Colors.Yellow); } }
void CanvasControl_Draw(Microsoft::Graphics::Canvas::UI::Xaml::CanvasControl^ sender,
Microsoft::Graphics::Canvas::UI::Xaml::CanvasDrawEventArgs^ args);
#include "pch.h" #include "MainWindow.xaml.h" using namespace App1; using namespace Microsoft::UI; using namespace Microsoft::Graphics::Canvas::UI::Xaml; MainWindow::MainWindow() { InitializeComponent(); } void MainWindow::CanvasControl_Draw(CanvasControl^ sender, CanvasDrawEventArgs^ args) { args->DrawingSession->DrawEllipse(155, 115, 80, 30, Colors::Black, 3); args->DrawingSession->DrawText("Hello, world!", 100, 100, Colors::Yellow); }
Imports Microsoft.UI Imports Microsoft.UI.Xaml.Controls Imports Microsoft.Graphics.Canvas.UI.Xaml Public NotInheritable Class MainWindow Inherits Page Public Sub New() Me.InitializeComponent() End Sub Private Sub CanvasControl_Draw(sender As CanvasControl, args As CanvasDrawEventArgs) args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.Black, 3) args.DrawingSession.DrawText("Hello, world!", 100, 100, Colors.Yellow) End Sub End Class
If you prefer to build your own version of Win2D from source, see the WinUI3 branch readme for instructions on how to clone from GitHub and compile it locally.