WinUI.Interop
0.3.0
dotnet add package WinUI.Interop --version 0.3.0
NuGet\Install-Package WinUI.Interop -Version 0.3.0
<PackageReference Include="WinUI.Interop" Version="0.3.0" />
paket add WinUI.Interop --version 0.3.0
#r "nuget: WinUI.Interop, 0.3.0"
// Install WinUI.Interop as a Cake Addin #addin nuget:?package=WinUI.Interop&version=0.3.0 // Install WinUI.Interop as a Cake Tool #tool nuget:?package=WinUI.Interop&version=0.3.0
WinUI.Interop
This package contains the interop wrappers for WinRT-APIs, that depend on CoreWindow
, and other interop helpers for WinUI Window
(e.g. to set an icon).
There are also some interop components that may help from inside an AppContainer like when using UWP.
This package is based on the work of AdamBraden/WindowsInteropWrappers.
Examples
WinUI3: window icon
The BuildAction
of the icon file has to be set to Embedded resource
in the Properties window!
using Microsoft.UI.Xaml;
using WinUI.Interop.NativeWindow;
namespace NAMESPACE
{
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.SetIcon("NAMESPACE.FILENAME.ico");
}
}
}
Win32: share content
using WinUI.Interop.CoreWindow;
IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;
DataTransferManager dataTransferManager = DataTransferManagerInterop.GetForWindow(hwnd);
dataTransferManager.DataRequested += DataTransferManager_DataRequested;
private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequestDeferral deferral = request.GetDeferral();
... // Implementation: https://docs.microsoft.com/en-us/windows/uwp/app-to-app/share-data
deferral.Complete();
}
DataTransferManagerInterop.ShowShareUIForWindow(Process.GetCurrentProcess().MainWindowHandle);
Win32: UWP dialog
TargetFramework >= net5.0
using WinRT;
using WinUI.Interop.CoreWindow;
FileSavePicker picker = new FileSavePicker();
picker.As<IInitializeWithWindow>().Initialize(Process.GetCurrentProcess().MainWindowHandle);
...
StorageFile file = await picker.PickSaveFileAsync();
...
TargetFramework < net5.0
using WinUI.Interop.CoreWindow;
FileSavePicker picker = new FileSavePicker();
(picker as object as IInitializeWithWindow).Initialize(Process.GetCurrentProcess().MainWindowHandle);
...
StorageFile file = await picker.PickSaveFileAsync();
...
RuntimeInformation
using WinUI.Interop;
RuntimeInformation.IsUWP;
RuntimeInformation.IsPackagedWin32;
RuntimeInformation.IsUnpackagedWin32;
RuntimeInformation.HasCapability("extendedExecutionBackgroundAudio");
UWP: Lowlevel audio control
using Windows.Media.Devices;
using WinUI.Interop.AppContainer;
IAudioEndpointVolume
is not part of this package! You have to implement the audio Interfaces yourself or use implementations from other libraries like naudio! docs.microsoft.com
public IAudioEndpointVolume VolumeManager { get; set; }
async void ...()
{
string deviceId = MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default);
VolumeManager = await AudioInterfaceActivator.ActivateAudioInterfaceAsync<IAudioEndpointVolume>(deviceId);
}
UWP: Handle of CoreWindow
using System;
using WinUI.Interop.CoreWindow;
IntPtr hWnd = CoreWindowInterop.CoreWindowHwnd;
or
IntPtr hWnd = CoreWindow.GetForCurrentThread().GetHwnd();
or
IntPtr hWnd = Window.Current.GetHwnd();
UWP: Handle of AppWindow
using System;
using WinUI.Interop.AppWindow;
AppWindow window = ...;
IntPtr hWnd = window.GetHwnd();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows10.0.19041 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Drawing.Common (>= 6.0.0)
-
net6.0-windows10.0.19041
- System.Drawing.Common (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on WinUI.Interop:
Package | Downloads |
---|---|
ShortDev.Uwp.FullTrust
Create a performant WinUI application with Uwp and CoreWindow and run as full-trust win32 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|