You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CameraCaptureUI] WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image #1034
Looks like the CameraCaptureUI does not support IInitializeWithWindow, and expects the caller to be on a CoreWindow thread. The implementation uses multiple pickers and launchers that need the "with window" treatment. It's an interesting candidate for open-sourcing the implementation for improvement.
Just do exactly like Apple and everything will be fine. I know this new Windows SDK is 15 years behind the SDK of Android and Apple, so I won't be too mean. Our app cannot release until we have access to the camera, we need to be able to scan documents with a camera.
Looks like the CameraCaptureUI does not support IInitializeWithWindow, and expects the caller to be on a CoreWindow thread. The implementation uses multiple pickers and launchers that need the "with window" treatment. It's an interesting candidate for open-sourcing the implementation for improvement.
CameraCaptureUI is probably implemented as a wrapper on Launcher::LaunchUriForResultsAsync as it opens the Windows Camera app in a modal dialog, but Launcher::LaunchUriForResultsAsync doesn't work in desktop apps.
Jon Wiswall (@jonwis) What happens with this issue, please? This bug is now included in official release of .NET MAUI. That's not good.
Reacted by Xyncgas, Arthur-Lee, Léo Carrière, Manfredi Marceca, gldfdp, Kyle Givler, Thorsten Sommer, Ben Owen, mhilkerEvapco, Christian Schmidt and 1 more
As an optional step, you can enable the "Send diagnostic data" option to help us gather data on the API’s reliability. Please check this box under: Privacy & security -> Diagnostics & Feedback -> Send Optional Diagnostic data!
We’d appreciate your feedback on whether the samples and API usage are clear, and if the fix works as expected
Reacted by ackh, BrunoBieri, Nikolay Pavlov and GuildOfCalamity
CameraCaptureUI cameraUI = new CameraCaptureUI(windowId);
This is not pleasant and something that should be improved. It must be possible to pass the current page / window / parent in the constructor, and it should be able to do the rest automatically.
var file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
It is a bit limiting that we can only capture on a file. Is it possible to extend the functionality of UWP, and capture on a stream?
Last, but not least: all these helpers in MainWIndow.xaml.cs must be integral part of the API without need for interop with Win32.
I think in the old days, UWP was sort of a "single window" world, so none of this mattered. But with WinUI and all the multi-window worlds, a modal dialog has to block some window and thus you need to specify which one.
Some magic could be added if you only have one window, then just use that. But, this now adds a layer of "worked when I did this, but now crashes with missing window errors" because the first test you only had 1 window, and the second test you had 3 windows.
I think it all has to do with the modal window idea. Maybe this API should not be blocking and have a non-modal option? So if you don't pass in a window ID then it just pops up a dialog with no blocking of the other windows.
Hi Nikolay Pavlov (@nikolayvpavlov)
Thank you for taking the time to test the new CameraCaptureUI API and for sharing your valuable feedback!
Regarding your points:
WindowId Constructor Parameters: We appreciate your suggestion to make the constructor more intuitive by passing the current page/window/parent directly. However, for now, we’ve kept the windowId parameter to ensure to support WinUi3 AppWindow (has Id()) & Window, and also Win32 apps which might be using HWNDs. Could you elaborate on the difficulties you see with the WindowId?
Capture on Stream: Great feedback. For WASDK1.7 release, our primary goal is to uplift the original UWP CameraCaptureUI API and support it in the WinAppSDK. We will explore it in upcoming release.
We believe the current behavior of blocking the window is by design. The CameraCaptureUI flow is intended to be a modal interaction, meaning it should start and complete before allowing other user interactions. This ensures the camera capture process is smooth and doesn’t conflict with other UI actions, there also might be hardware limitations.
Could you elaborate on the issue you mentioned: "worked when I did this, but now crashes with missing window errors"?
WindowId Constructor Parameters: We appreciate your suggestion to make the constructor more intuitive by passing the current page/window/parent directly. However, for now, we’ve kept the windowId parameter to ensure to support WinUi3 AppWindow (has Id()) & Window, and also Win32 apps which might be using HWNDs. Could you elaborate on the difficulties you see with the WindowId?
The problem is not in the constructor, but the whole effort that must be taken in advance to retrieve the current window id. Quoting your sample:
// We have exposed a public variable called MainWindow in App.xaml.cs to fetch the window.
var windowId = ((App)Application.Current).MainWindow.AppWindow.Id;
The comment speaks a lot. One must customize your App class just to get the main window in order to get the Window Id. It will not work if we have a multi-window app where developers must store the instance of each window and implement a way to find the right instance they need. Several APIs rely on window id to work (all that require a CoreWindow, if I am not mistaken). WinUI must provide an easy way to get the current window (based on parenthood).
Perhaps the Window (Id) can be propagandized down to certain controls which are typically the main containers and whose code-behind orchestrate the behavior, such as Page, Alternatively there can be some helpers to find the window id based on parenthood. Such common tasks must not be off-loaded to developer to reinvent all the time. For example, UIElement may have a method like GetWindow() which returns their container window, if any, or null.
changed the title [-]WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/-][+][CameraCaptureUI] WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/+]on Nov 5, 2025
Activity
jgkumaran commentedon Jul 14, 2021
I think CameraCaptureUI requires you to invoke IInitializeWithWindow and pass the window handle.
sangitamalviya commentedon Jul 19, 2021
hi @Jaiganeshkumaran , https://gist.github.com/wbokkers/cc8bcc7bc5a646b82a4d41b337330c69 here FileOpenPicker IInitializeWithWindow . I was same tried for CameraCaptureUI IInitializeWithWindow,but it's giving Exception "Element Not Found".I do not know CameraCaptureUI have different Guid or not.
jonwis commentedon Jul 19, 2021
Looks like the
CameraCaptureUIdoes not supportIInitializeWithWindow, and expects the caller to be on aCoreWindowthread. The implementation uses multiple pickers and launchers that need the "with window" treatment. It's an interesting candidate for open-sourcing the implementation for improvement.craigomatic commentedon Aug 12, 2021
Is there any workaround in the meantime?
applefanbois commentedon Dec 29, 2021
Just do exactly like Apple and everything will be fine. I know this new Windows SDK is 15 years behind the SDK of Android and Apple, so I won't be too mean. Our app cannot release until we have access to the camera, we need to be able to scan documents with a camera.
jgkumaran commentedon Dec 29, 2021
CameraCaptureUI is probably implemented as a wrapper on Launcher::LaunchUriForResultsAsync as it opens the Windows Camera app in a modal dialog, but Launcher::LaunchUriForResultsAsync doesn't work in desktop apps.
JoeyLiang-0 commentedon Jan 19, 2022
Any update on this issue?
applefanbois commentedon Jan 19, 2022
No, surely things will get resolved over time. After all, the hide-task-bar is still not working half the time 25 years later in Windows 11.
janseris commentedon Jun 10, 2022
Jon Wiswall (@jonwis) What happens with this issue, please? This bug is now included in official release of .NET MAUI. That's not good.
XeonKHJ commentedon Jun 16, 2022
Still wating for this issue to be resolved.
27 remaining items
Saharsh979 commentedon Dec 3, 2024
Hi everyone,
We’ve added a new CameraCaptureUI API as part of the WASDK 1.7 Experimental 1 release. The updated API is now available, and we've also added samples for both C++ and C# to demonstrate its usage.
WindowsAppSDK-Samples/Samples/CameraCaptureUI at release/experimental · microsoft/WindowsAppSDK-Samples
To test, please retarget your project to WASDK version 1.7.241114004-experimental1.
As an optional step, you can enable the "Send diagnostic data" option to help us gather data on the API’s reliability. Please check this box under: Privacy & security -> Diagnostics & Feedback -> Send Optional Diagnostic data!
We’d appreciate your feedback on whether the samples and API usage are clear, and if the fix works as expected
nikolayvpavlov commentedon Dec 4, 2024
CameraCaptureUI cameraUI = new CameraCaptureUI(windowId);This is not pleasant and something that should be improved. It must be possible to pass the current page / window / parent in the constructor, and it should be able to do the rest automatically.
var file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);It is a bit limiting that we can only capture on a file. Is it possible to extend the functionality of UWP, and capture on a stream?
Last, but not least: all these helpers in MainWIndow.xaml.cs must be integral part of the API without need for interop with Win32.
mattleibow commentedon Dec 4, 2024
I think in the old days, UWP was sort of a "single window" world, so none of this mattered. But with WinUI and all the multi-window worlds, a modal dialog has to block some window and thus you need to specify which one.
Some magic could be added if you only have one window, then just use that. But, this now adds a layer of "worked when I did this, but now crashes with missing window errors" because the first test you only had 1 window, and the second test you had 3 windows.
I think it all has to do with the modal window idea. Maybe this API should not be blocking and have a non-modal option? So if you don't pass in a window ID then it just pops up a dialog with no blocking of the other windows.
Saharsh979 commentedon Dec 10, 2024
Hi Nikolay Pavlov (@nikolayvpavlov)
Thank you for taking the time to test the new CameraCaptureUI API and for sharing your valuable feedback!
Regarding your points:
WindowId Constructor Parameters: We appreciate your suggestion to make the constructor more intuitive by passing the current page/window/parent directly. However, for now, we’ve kept the windowId parameter to ensure to support WinUi3 AppWindow (has Id()) & Window, and also Win32 apps which might be using HWNDs. Could you elaborate on the difficulties you see with the WindowId?
Capture on Stream: Great feedback. For WASDK1.7 release, our primary goal is to uplift the original UWP CameraCaptureUI API and support it in the WinAppSDK. We will explore it in upcoming release.
Saharsh979 commentedon Dec 10, 2024
Matthew Leibowitz (@mattleibow) Thank you for sharing your thoughts.
We believe the current behavior of blocking the window is by design. The CameraCaptureUI flow is intended to be a modal interaction, meaning it should start and complete before allowing other user interactions. This ensures the camera capture process is smooth and doesn’t conflict with other UI actions, there also might be hardware limitations.
Could you elaborate on the issue you mentioned: "worked when I did this, but now crashes with missing window errors"?
nikolayvpavlov commentedon Dec 16, 2024
Hi Saharsh Ananta Jaiswal (@Saharsh979) ,
Many thanks for following up.
The problem is not in the constructor, but the whole effort that must be taken in advance to retrieve the current window id. Quoting your sample:
The comment speaks a lot. One must customize your App class just to get the main window in order to get the Window Id. It will not work if we have a multi-window app where developers must store the instance of each window and implement a way to find the right instance they need. Several APIs rely on window id to work (all that require a CoreWindow, if I am not mistaken). WinUI must provide an easy way to get the current window (based on parenthood).
Perhaps the Window (Id) can be propagandized down to certain controls which are typically the main containers and whose code-behind orchestrate the behavior, such as Page, Alternatively there can be some helpers to find the window id based on parenthood. Such common tasks must not be off-loaded to developer to reinvent all the time. For example,
UIElementmay have a method likeGetWindow()which returns their container window, if any, or null.lhak commentedon Dec 16, 2024
The
XamlRoot.ContentIslandEnvironment.AppWindowId()method should give you the window for a certain UI element.[-]WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/-][+][CameraCaptureUI] WinUi 3 desktop app doesn't open camera. and is there any way that can open default system camera and capture image[/+]