Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x:Bind to built-in control ActualTheme fails to compile in C++ #10389

Open
HO-COOH opened this issue Feb 26, 2025 · 0 comments
Open

x:Bind to built-in control ActualTheme fails to compile in C++ #10389

HO-COOH opened this issue Feb 26, 2025 · 0 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@HO-COOH
Copy link

HO-COOH commented Feb 26, 2025

Describe the bug

The exact code works in C#.
Obviously in C++, it generates the wrong code. For example, if I have <TextBlock Text="{x:Bind local:MyPage.ElementThemeToString(MyButton.ActualTheme), Mode=OneWay}" />, it generates

        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
    <StackPanel>
        <Button x:Name="MyButton" />
        <TextBlock Text="{x:Bind local:MyPage.ElementThemeToString(MyButton.ActualTheme), Mode=OneWay}" />
    </StackPanel>

in code behind, simply return a string

        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";
            }
        }
  1. 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

@HO-COOH HO-COOH added the bug Something isn't working label Feb 26, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant