I’d like to use an F# project to draw onto a Win2D CanvasControl in a WinUI3 application.
The process would be something like:
-
User does something - presses a button, slides a slider, etc. - in the WinUI3 application;
-
This sends a ‘current state’ to a function in StateProject (F#);
-
Which modifies the state and returns a new ‘current state’ to the WinUI3 application;
-
Which then invalidates the CanvasComponent;
-
The Draw method of which sends the ‘current state’ (and some other stuff) to a function in DrawingProject (F#);
-
Which draws on the CanvasComponent.
The ‘current state’ will be boxed when passed between projects so that the WinUI3 application cannot modify or see the contents, and unboxed when in the F# projects (because the state contains F#-only things, e.g. DUs, Lists, etc.).
The overall reasoning is that the StateProject does all of the state set-up and modification, DrawingProject only does the drawing, and the WinUI3 application just uses the F# projects as necessary, removing most of the ‘work’ from the application itself.
I tried to add Microsoft.Graphics.Win2D as a package of DrawingProject but that project failed to compile with errors that I didn’t recognise or understand (it even had a problem with the ‘namespace’ keyword which was the first bit of text in the only .fs file in the project).
I’ve looked at the dependencies for Win2D and it’s dependent upon Microsoft.WindowsAppSDK which is itself dependent upon Microsoft.Web.WebView2 and Microsoft.Windows.SDK.BuildTools, which I think are a bit too much to add to a little F# project that just needs to draw some basic things.
Has anyone managed to get this sort of thing working and, if so, how?
Note: Whatever is done needs to be compatible with .NET between 6.0 and 8.0 (inclusive) because of WinUI3 restrictions.