Open bryankeller opened 3 years ago
If this isn't from inside a UWP, maybe check out https://github.com/dotnet/core/issues/5670 ? The capture picker needs to know which window to parent against when displaying its own experience.
(@AdamBraden FYI)
Thanks @jonwis - pretty new to windows dev so appreciate the tip. I did come across that thread, but I'm not sure if doing the workaround from that thread you linked to works in project reunion
https://github.com/dotnet/core/issues/5670#issuecomment-737903026
Maybe I'm missing an import, not sure which though.
Hey @rkarman / @AdamBraden / @angelazhangmsft - here's a place we could use some more samples and helpers. Check out what this sample does and what this C#/WinRT sample does.
IWindowNative
from your Window
typeWindowHandle
(the underlying HWND
) as an IntPtr
IInitializeWithWindow
from your GraphicsCaptureSession
and call Initialize
with the IntPtr
on it(And yes, the use of the window interop helper type on WinUI3 types from WinAppSDK should work just fine, and we'll get a sample written to show it.)
@bryankeller, We recently added helpers in C#/.NET for the classes that require IInitializeWithWindow to associate the object with a window handle in desktop apps. There is documentation on the C# helpers here. In your scenario, you should be able to use this code:
var picker = new Windows.Graphics.Capture.GraphicsCapturePicker();
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);
var item = await picker.PickSingleItemAsync();
...
@bryankeller Another thing to call out given you are seeing a wrong thread error is, I would make sure you are on a recent version of the .NET 5 SDK as we did have some fixes a couple months ago in the Windows SDK projection for that error.
@bryankeller - are you still running into this issue?
Whenever I call
PickSingleItemAsync
on aGraphicsCapturePicker
, I get a runtime error:I'm using Visual Studio 2019, WinUI 1.8, and I'm running Windows 10 10.0.19042. Here's my code - a simple button (defined in my XAML) is what's calling
StartCapture
.