microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

ResourceDictionary Controls trigger runtime error with embedded CanvasControl from Microsoft.Graphics.Win2D

Open StevoSM opened this issue 7 months ago • 2 comments

Describe the bug

Adding Microsoft.Graphics.Win2D to a Project and embedding a CanvasControl in a Window or even UserControl works great. However, when embedding a CanvasControl in a ResourceDictionary control, it results in a runtime error, which isn't consistent.

The attached solution demonstrates the issue. It is configured to show a CanvasControl in all 3 scenarios.

Win2DSandbox.zip

Steps to reproduce the bug

Open provided solution and ensure packages are installed. Build and run. See crash happen.

Expected behavior

No crash

Screenshots

No response

NuGet package version

None

Windows version

Windows 10 (21H2): Build 19044

Additional context

No response

StevoSM avatar Apr 30 '25 07:04 StevoSM

@StevoSM I see the related discussion was closed and you were able to get around your issue. Do you still need support on this bug, or we are good to close.

hiteshkrmsft avatar Jun 04 '25 06:06 hiteshkrmsft

@hiteshkrmsft Because of other issues with Templated Controls, we had to abandon them for the time being and switch to User Controls. Whichever path one desires, I would think it should be possible to include and use Win2D to help render content. While this approach works with User Controls no problem, you get a crash deep in WinUI when trying this with Templated Controls. The attached project demonstrates the crash - simply build and run. Since we had to switch to User Controls, we are not triggering any issues, however, I would expect others to try to use Win2D with Templated Controls and expect it to work, so I would expect you would want to fix this crash if possible.

StevoSM avatar Jun 05 '25 01:06 StevoSM