Warning
This package is no longer maintained, as there are better 1st and 3rd party libraries.
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.
Tip
Use WinUIEx instead
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");
}
}
}
Tip
Use DataTransferManagerInterop
with CsWinRT instead
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);
Tip
Use IInitializeWithWindow
with CsWinRT instead
using WinRT;
using WinUI.Interop.CoreWindow;
FileSavePicker picker = new FileSavePicker();
picker.As<IInitializeWithWindow>().Initialize(Process.GetCurrentProcess().MainWindowHandle);
...
StorageFile file = await picker.PickSaveFileAsync();
...
using WinUI.Interop.CoreWindow;
FileSavePicker picker = new FileSavePicker();
(picker as object as IInitializeWithWindow).Initialize(Process.GetCurrentProcess().MainWindowHandle);
...
StorageFile file = await picker.PickSaveFileAsync();
...
Tip
Use ShortDev.Uwp.FullTrust instead
using WinUI.Interop;
RuntimeInformation.IsUWP;
RuntimeInformation.IsPackagedWin32;
RuntimeInformation.IsUnpackagedWin32;
RuntimeInformation.HasCapability("extendedExecutionBackgroundAudio");
Tip
Use ActivateAudioInterfaceAsync
with CsWin32 instead
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);
}
Tip
Use ICoreWindowInterop
with CsWinRT instead
using System;
using WinUI.Interop.CoreWindow;
IntPtr hWnd = CoreWindowInterop.CoreWindowHwnd;
or
IntPtr hWnd = CoreWindow.GetForCurrentThread().GetHwnd();
or
IntPtr hWnd = Window.Current.GetHwnd();
using System;
using WinUI.Interop.AppWindow;
AppWindow window = ...;
IntPtr hWnd = window.GetHwnd();