Comments (2)
Interesting question! I don't know F# well, but if I am correctly interpreting what I see in Visual Studio, I think this issue is due to the lack of a non-PCL F# library template supporting Windows Store.
PCL (Portable Class Library) is a very restricted subset that can only reference APIs that are universally available on all the enabled target platforms. Because Win2D is a WinRT component implemented using native code, it is not accessible from a PCL.
In C#, there are two options for library projects:
- Store Apps / Universal Apps / Class Library (Portable for Universal Apps) is a PCL, so cannot reference Win2D
- Store Apps / Windows Apps / Class Library (Windows) is a regular (non-PCL) class library that supports Windows Store and can reference Win2D
But when I look at the F# project templates, I see only:
- Library (which is not for Windows Store)
- Portable Library (which is a PCL)
I'm not sure why F# is missing the option of a non-PCL library project that targets Windows Store, but without this I don't think it will be possible to directly access Win2D. At least not currently - we will do some more digging to see if there isn't some way we might be able to support PCL better, but I'm not sure how or even if that may be possible.
You could use the C# "Class Library (Windows)" project type as a proxy except I suspect this will run into the same issue that you won't be able to reference that C# project from an F# PCL.
Unless I'm missing something, it looks like F# support for calling WinRT APIs is currently not very complete, or at least that Visual Studio does not include a full set of templates for this type of project.
from win2d.
Hello again - I spent some more time looking into this and here's what I found out:
-
There is not currently any good way to consume a WinRT component such as Win2D from a .NET portable class library (PCL) like the default F# project type. There's nothing we can change in the Win2D packaging to make that work.
-
This means that to access Win2D from F#, you would need to create a non-PCL F# project targeting the Windows Store platform. Unfortunately there does not seem to be any support for this in F#, although I am extremely newbie in the world of F# so might just not be aware how to do it.
-
One structure that will work is to implement your app logic as an F# PCL, then consume the resulting F# assembly from a C# app project which can use Win2D to draw the data that was calculated by F# code. The project dependencies only work this way around, though: C# Windows Store project using Win2D can call into F# PCL, but it is not possible for an F# PCL to call into a C# Windows Store library project (F# PCL can only call C# library if that C# library is also PCL, in which case the C# PCL library could not use Win2D).
Hope that helps,
from win2d.
Related Issues (20)
- Somthing is wrong with `Microsoft::Graphics::Canvas::CanvasBitmap::CreateFromBytes` (not straight forward to call it)
- Use non-version-specific RID folders in NuGet package HOT 2
- Upgrade to v1.1.0 causes compiler error HOT 4
- `CanvasDrawingSession.DrawGlyphRun` renders emojis in monochrome when using color font and `CanvasDrawTextOptions.EnableColorFont` option HOT 2
- A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll HOT 1
- How to enable Windows 11's Auto HDR feature on Win2D?
- Changelog for Win2D.uwp 1.27.1 HOT 3
- CanvasTextFormat throws in Unpackaged apps HOT 19
- Microsoft.Graphics.Canvas.winmd cannot be referenced HOT 5
- Microsoft.Graphics.Win2D fail to work with winui after 1.1.0 HOT 3
- Doc Bug in readme.md
- .net8 Cannot create instance of type Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl HOT 1
- Installing the NuGet package results in a fatal error HOT 3
- Exception thrown: 'System.TypeInitializationException' in Microsoft.Graphics.Canvas.Interop.dll
- Strange problem with Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder HOT 13
- Question about performance
- Error installing Win2D NuGet in WinUI3 app HOT 2
- Text Color Bleeding Out of Outline HOT 2
- The print preview is very blurry at 200% zoom.
- Access Violation App Crash
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from win2d.