InteropCompositor 1.0.0
dotnet add package InteropCompositor --version 1.0.0
NuGet\Install-Package InteropCompositor -Version 1.0.0
<PackageReference Include="InteropCompositor" Version="1.0.0" />
paket add InteropCompositor --version 1.0.0
#r "nuget: InteropCompositor, 1.0.0"
// Install InteropCompositor as a Cake Addin #addin nuget:?package=InteropCompositor&version=1.0.0 // Install InteropCompositor as a Cake Tool #tool nuget:?package=InteropCompositor&version=1.0.0
Interop Compositor
With the release of .NET5 Preview 8, Microsoft introduced a streamlined way for .NET developers to access the set of Windows Runtime (WinRT) APIs that are shipped as part of Windows..NET5 applications can now access Windows APIs through a new set of Target Framework Monikers (TFMs), which have been extended to support platform specific APIs.
This change means that applications targeting .NET5 no longer need to reference the Microsoft.Windows.SDK.Contracts
NuGet package.
But in Target Framework Moniker Using Compositor
object to get ICompositorDesktopInterop
throws exception
System.PlatformNotSupportedException: 'Marshalling as IInspectable is not supported in the .NET runtime.'
To overcome this issue you can use InteropCompositor.
Install
NuGet Package
Install-Package InteropCompositor
https://nuget.org/packages/InteropCompositor
Usage
Set the TargetFramework in the project file
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
and in your code use
Compositor compositor = new Compositor();
ICompositorDesktopInterop interop = compositor.TryAs<ICompositorDesktopInterop>();
interop.CreateDesktopWindowTarget(hwnd, true, out var target).ThrowOnError();
ICompositionTarget compositionTarget = (ICompositionTarget)target;
Note: Don't forget to create DispatcherQueueController
on MainWindow Constructor.
Credits 🏅
Simon Mourier and his Repository DirectN
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0-windows10.0.19041 is compatible. net6.0-windows was computed. net7.0-windows was computed. net8.0-windows was computed. |
-
net5.0-windows10.0.19041
- 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 |
---|---|---|
1.0.0 | 575 | 8/26/2021 |