FileOpenPicker does not work in Page
See original GitHub issueDescribe the bug
When you try to open FileOpenPicker in a page, nothing works. Nothing can be opened or the application simply closes. But on a window page it does work.
Steps to reproduce the bug
-
i create a page
-
i insert the following code: `` try { FileOpenPicker folderPicker = new(); folderPicker.ViewMode = PickerViewMode.List; folderPicker.SuggestedStartLocation = PickerLocationId.Desktop; folderPicker.FileTypeFilter.Add(“.jpg”); folderPicker.FileTypeFilter.Add(“.jpeg”); folderPicker.FileTypeFilter.Add(“.png”);
var hwd = WindowNative.GetWindowHandle(this); WinRT.Interop.InitializeWithWindow.Initialize(folderPicker, hwd); var file = await folderPicker.PickSingleFileAsync();
} catch (Exception ex) { ``
-
nothing happens during testing
Expected behavior
No response
Screenshots
No response
NuGet package version
None
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
Issue Analytics
- State:
- Created 2 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
FileOpenPicker not working in C# on Windows 11 Desktop
I am creating a Windows Form App in VS on Windows11 and get this error when I attempt to run my file picker...
Read more >FileOpenPicker Class (Windows.Storage.Pickers)
Represents a UI element that lets the user choose and open files. In a desktop app, before using an instance of this class...
Read more >Preview 4 - FolderPicker and FilePicker not working / App ...
Simple to reproduce: I have downloaded VisualStudio 2019 Preview Version 16.9 and installed with WinUI 3 preview 4.
Read more >How to use FilePicker and FolderPicker in WinUI 3 and ...
I use the navigation view. The window handle works as I can execute the FileOpenPicker, as in the example code showed. So I...
Read more >Object initialization can be simplified : var picker = new ...
Your open channel to Microsoft engineering teams. Select a page ... I do not like to suppress suggestions that I think are not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Window is documented to implement IWindowNative (which WindowNative uses). In fact, IWindowNative documents that only Window implements the interface. What this basically means is that IWindowNative::get_WindowHandle/WindowNative.GetWindowHandle can only be used from something that derives from Microsoft.UI.Xaml.Window. So you will have to add some means for your page to obtain the main window. You can use your App class for this.
Ok, sorry