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

Control with Win11 theming falls back to "old" theming when applying a style #10054

Open
Zagrthos opened this issue Nov 12, 2024 · 5 comments
Open
Assignees

Comments

@Zagrthos
Copy link

Description

When applying a custom style to a control which is themed via the Windows 11 MergedDictionary it falls back to the old theming.

Reproduction Steps

Create a new WPF Window and add a TabControl with TabItems to it. Then apply the following style to the window:

<Window.Resources>
    <Style TargetType="TabItem">
        <Setter Property="FontWeight" Value="Normal"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="FontWeight" Value="Bold"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

Expected behavior

The style is just added without removing the theming.

Actual behavior

Fallback to old theming
Image

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

  • .NET Version: 9.0.100-rc.2.24474.11
  • OS: Windows 11 22635.4445
  • Arch: x64

Other information

Maybe I am too new to WPF and that's expected, because it's wanted by design, but for me right now it's appears like a (possible) bug.

@Zagrthos Zagrthos changed the title Win11 theme falls back to "old" one when applying a style Control with Win11 theming falls back to "old" theming when applying a style Nov 12, 2024
@dipeshmsft
Copy link
Member

dipeshmsft commented Nov 12, 2024

@Zagrthos, you are right. Since, you mentioned you are new, I will dig a little deep into this here.

All the FrameworkElements have two properties : Style and ThemeStyle .
Before Fluent, for all the themes, the default control style was loaded in ThemeStyle property, leaving the Style property to be set by the user. In use cases like you have mentioned above ( where not all the properties are set in the custom style ), the remaining part of the style was picked up from style loaded in ThemeStyle property.

Fluent theme styles require more flexibility in terms of customizability and resource usage as compared to other themes, and so in the current system, the Fluent styles are loaded in the Style property. Whereas, Aero2 is still being loaded in the ThemeStyle property.

Now, when you provided your own style, the Fluent style got replaced and your style is being loaded in the FrameworkElement's Style property, and since only some of the properties are defined in the custom style rest of them are being picked from ThemeStyle ( i.e. Aero2 ) style.

We will work on a fix for this.

@Zagrthos
Copy link
Author

@dipeshmsft thanks for your kind explanation and the reply! I'm still trying to fiddle with WPF, tried it a few times already but XAML and MVVM scared me off a lot. Hopefully that'll work out now 😀

@miloush
Copy link
Contributor

miloush commented Nov 12, 2024

I am not quite sure how this is expected to be fixed, there will always be "unexpected' ways people accidentally remove it. That's why there is ThemeStyle and why the Fluent theme needs to be loaded the same way. And you didn't run into the precedence issues yet.

EDIT: I might have read this too fast, this looks like a precedence issue.

@aquinn39
Copy link

As a workaround, you can set BasedOn property of the Style to {StaticResource DefaultCONTROLNAMEHEREstyle}, but be aware that that will crash when the old themes are used.

@dipeshmsft
Copy link
Member

@aquinn39 is right, initially I wrote that in my comment, but then it was pointed out by @harshit7962, that we missed giving a Key to TabItem style and then I removed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants