question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileOpenPicker does not work in Page

See original GitHub issue

Describe 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

  1. i create a page

  2. 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) { ``

  3. 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:closed
  • Created 2 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DarranRowecommented, Aug 5, 2023

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.

0reactions
Steff093commented, Aug 5, 2023

Ok, sorry

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found