Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Last active March 18, 2022 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/cb78543caa8a9b3dd0030d674e9666fa to your computer and use it in GitHub Desktop.
Save jfversluis/cb78543caa8a9b3dd0030d674e9666fa to your computer and use it in GitHub Desktop.
using WindowsFolderPicker = Windows.Storage.Pickers.FolderPicker;
namespace MauiFolderPickerSample.Platforms.Windows
{
public class FolderPicker : IFolderPicker
{
public async Task<string> PickFolder()
{
var folderPicker = new WindowsFolderPicker();
// Get the current window's HWND by passing in the Window object
var hwnd = ((MauiWinUIWindow)App.Current.Windows[0].Handler.PlatformView).WindowHandle;
// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(folderPicker, hwnd);
var result = await folderPicker.PickSingleFolderAsync();
return result.Path;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment