Skip to content

Instantly share code, notes, and snippets.

@emoacht
Created June 3, 2022 13:52
Show Gist options
  • Save emoacht/195e6c34ee935726b3fcdbc6cd9bc043 to your computer and use it in GitHub Desktop.
Save emoacht/195e6c34ee935726b3fcdbc6cd9bc043 to your computer and use it in GitHub Desktop.
Set owner window before .NET 5.0.
[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
public void SetOwnerWindow(StoreContext context, Window window)
{
var handle = new WindowInteropHelper(window).Handle;
var initWindow = (IInitializeWithWindow)(object)context;
initWindow.Initialize(handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment