microsoft / microsoft/microsoft-ui-xaml
ThemeResource failed to assign to custom property
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
I have a custom templated control, and I want to bind its property to a `ThemeResource`, and I got crash at xaml loading phase during app launch.
### Steps to reproduce the bug
1. Create a new WinUI3 C++ packaged project
2. Create a new templated control, with this idl
```idl
[default_interface]
runtimeclass MyControl : Microsoft.UI.Xaml.Controls.Control
{
MyControl();
String StringProperty;
}
```
3. In `MainWindow.xaml`, use this code
```xml
Light
Dark
```
4. Build and run, see the crash
### Expected behavior
_No response_
### Screenshots

### NuGet package version
WinUI 3 - Windows App SDK 1.6 Preview 1: 1.6.240807006-preview1
### Windows version
Windows 11 (22H2): Build 22621
### Additional context
Making it to a `DependencyProperty` does not solve this issue.
I tried and this issue also happens in UWP too.
[Repro](https://github.com/HO-COOH/WinUI-Bug/tree/main/15-CustomThemeResourceException)
Contributor guide
Research direction
Start by running the linked 15-CustomThemeResourceException reproduction and inspect MainWindow.xaml, the MyControl IDL, and the ThemeResource assignment during XAML loading. Done means the custom control loads without a crash and StringProperty resolves to the correct Light or Dark resource.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100