microsoft / microsoft/microsoft-ui-xaml
x:Bind to built-in control ActualTheme fails to compile in C++
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
The exact code works in C#.
Obviously in C++, it generates the wrong code. For example, if I have ``, it generates
```cpp
void DependencyPropertyChanged(DependencyObject const& sender, DependencyProperty const& prop) override
{
if (sender)
{
if (sender == cacheDPC_MyButton_ActualTheme && ::winrt::Microsoft::UI::Xaml::Controls::Button::ActualThemeProperty() == prop)
```
The `ActualThemeProperty()` is in `FrameworkElement` not in `Button`, so it fails.
Curiously, {x:Bind} to my custom UserControl compiles fine, generates the correct code.
### Steps to reproduce the bug
1. Create a C++ packaged project
2. Create a new Page (in case you say it's because of Window), Use this xaml
```xml
```
in code behind, simply return a string
```cpp
static winrt::hstring ElementThemeToString(winrt::Microsoft::UI::Xaml::ElementTheme theme)
{
switch (theme)
{
case winrt::Microsoft::UI::Xaml::ElementTheme::Dark: return L"Dark";
case winrt::Microsoft::UI::Xaml::ElementTheme::Light: return L"Light";
default: return L"Default";
}
}
```
3. Build the project
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.6.5: 1.6.250205002
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
_No response_
Contributor guide
Research direction
Reproduce the C++ packaged project using the provided XAML binding and ElementThemeToString method. Start by tracing x:Bind code generation for MyButton.ActualTheme, especially the generated DependencyPropertyChanged comparison, and compare the owner type used for ActualThemeProperty with the FrameworkElement declaration. Done means the project builds with the built-in control binding and the generated property reference is valid.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100