# Can I use Microsoft.Graphics.Win2D in an F# project?

**URL:** <https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522>\
**Category:** General\
**Tags:** beginners\
**Created:** [May 7, 2025, 1:29pm UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522 "2025-05-07T13:29:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GarryP](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@GarryP](https://forums.fsharp.org/u/GarryP)\
**Post date:** [May 7, 2025, 1:29pm UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522/1 "2025-05-07T13:29:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![altbodhi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/altbodhi/32/1253_2.png) [@altbodhi](https://forums.fsharp.org/u/altbodhi)\
**Post date:** [May 13, 2025, 9:44am UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522/2 "2025-05-13T09:44:31Z")

</div>

I think you need learn docs and I recommend to see [Elmish · Elmish](https://elmish.github.io/elmish/) for build UI.

---

<div class="post-metadata">

**Author:** ![GarryP](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@GarryP](https://forums.fsharp.org/u/GarryP)\
**Post date:** [May 15, 2025, 11:22am UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522/3 "2025-05-15T11:22:03Z")

</div>

Thanks but I can’t see how that would meet my requirements.

I should have said earlier that I need to draw procedurally generated shapes – rectangles, ellipses, polylines, etc. – which are created by some F# code.

And I am using Win2D to do that because I have a WinUi3 application.

And I have a WinUi3 application because I have no idea how to package an F# project for the Microsoft Store (or if that’s even possible).

I think I’ve managed to ‘smudge’ my requirements by returning a sequence of intermediate objects from the F# code to be used in the C# drawing code and I’m hoping that the overhead of doing so won’t affect the result too much (some quick tests look promising so far).

---

<div class="post-metadata">

**Author:** ![GarryP](https://avatars.discourse-cdn.com/v4/letter/g/da6949/32.png) [@GarryP](https://forums.fsharp.org/u/GarryP)\
**Post date:** [July 2, 2025, 1:32pm UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522/6 "2025-07-02T13:32:33Z")

</div>

Welcome to the community Clark Dahl.

Thanks, yes, that’s what I’ve been doing.

The ‘overhead’ of doing so doesn’t seem to be a problem for my current needs.

---

<div class="post-metadata">

**Author:** ![altbodhi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/altbodhi/32/1253_2.png) [@altbodhi](https://forums.fsharp.org/u/altbodhi)\
**Post date:** [July 11, 2025, 7:09am UTC](https://forums.fsharp.org/t/can-i-use-microsoft-graphics-win2d-in-an-f-project/4522/7 "2025-07-11T07:09:02Z")

</div>

F# very similar to C# because both based on clr. F# support class like as C#. You can write C# in F# syntax. Do not focus only on pure functional programming. F# multiparadigm language.
