-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoragePicker.cs
65 lines (55 loc) · 2.26 KB
/
StoragePicker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using System.Runtime.InteropServices;
using WinRT;
using Windows.Storage.Pickers;
namespace ImageOverlay
{
public static class WindowsStoragePickersExtensions
{
[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("EECDBF0E-BAE9-4CB6-A68E-9598E1CB57BB")]
internal interface IWindowNative
{
IntPtr WindowHandle { get; }
}
/// <summary>
/// Sets the owner window for this <see cref="FileOpenPicker"/>. This is required when running in WinUI for Desktop.
/// </summary>
public static void SetOwnerWindow(this FileOpenPicker picker, Window window)
{
SetOwnerWindow(picker.As<IInitializeWithWindow>(), window);
}
/// <summary>
/// Sets the owner window for this <see cref="FileSavePicker"/>. This is required when running in WinUI for Desktop.
/// </summary>
public static void SetOwnerWindow(this FileSavePicker picker, Window window)
{
SetOwnerWindow(picker.As<IInitializeWithWindow>(), window);
}
/// <summary>
/// Sets the owner window for this <see cref="FolderPicker"/>. This is required when running in WinUI for Desktop.
/// </summary>
public static void SetOwnerWindow(this FolderPicker picker, Window window)
{
SetOwnerWindow(picker.As<IInitializeWithWindow>(), window);
}
private static void SetOwnerWindow(IInitializeWithWindow picker, Window window)
{
// See https://github.com/microsoft/microsoft-ui-xaml/issues/4100#issuecomment-774346918
picker.Initialize(window.As<IWindowNative>().WindowHandle);
}
}
}