question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to change the caption button foreground based on themes(light/dark) [WinUI 3 WinAppSDK 1.1p2]

See original GitHub issue

The documentation mentioned that we can customise the foreground of the caption buttons by defining resources in app.xaml. This neatly sets the colors but these colors are not responsive to the change in the theme.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
            <!-- Other merged dictionaries here -->
        </ResourceDictionary.MergedDictionaries>
        <!-- Other app resources here -->
        <SolidColorBrush x:Key="WindowCaptionBackground">Green</SolidColorBrush>
        <SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">LightGreen</SolidColorBrush>
        <SolidColorBrush x:Key="WindowCaptionForeground">Red</SolidColorBrush>
        <SolidColorBrush x:Key="WindowCaptionForegroundDisabled">Pink</SolidColorBrush>
    </ResourceDictionary>
</Application.Resources>

I have tried defining these resources in the Dark and Light section of the dictionary, however I could not make it work. Is it that the caption buttons are ignoring these changes? or I am doing something incorrect. My App is based on WinAppSDK 1.1 preview 2.

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /><ResourceDictionary>
                    <ResourceDictionary.ThemeDictionaries>
                        <ResourceDictionary x:Key="Default">
                            <Color x:Key="CaptionColor">#FFFFFF</Color>
                            <Color x:Key="CaptionColorDisabled" >#5DFFFFFF</Color>
                        </ResourceDictionary>
                        <ResourceDictionary x:Key="Light">
                            <Color x:Key="CaptionColor">#E4000000</Color>
                            <Color x:Key="CaptionColorDisabled" >#5C000000</Color>
                        </ResourceDictionary>
                        <ResourceDictionary x:Key="Dark">
                            <Color x:Key="CaptionColor">#FFFFFF</Color>
                            <Color x:Key="CaptionColorDisabled" >#5DFFFFFF</Color>
                        </ResourceDictionary>
                        <ResourceDictionary x:Key="HighContrast">
                            <Color x:Key="CaptionColor">#E4000000</Color>
                            <Color x:Key="CaptionColorDisabled" >#5C000000</Color>
                        </ResourceDictionary>
                    </ResourceDictionary.ThemeDictionaries>
                    <SolidColorBrush x:Key="WindowCaptionForeground" Color="{ThemeResource CaptionColor}"/>
                    <SolidColorBrush x:Key="WindowCaptionForegroundDisabled" Color="{ThemeResource CaptionColorDisabled}" />
                    <SolidColorBrush x:Key="WindowCaptionBackground" Color="Transparent"/>
                    <SolidColorBrush x:Key="WindowCaptionBackgroundDisabled" Color="Transparent" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ghost1372commented, Apr 22, 2022

@harvinders i have this issue too, i used c# code for doing this. you can find my codes in ThemeHelper class https://github.com/ghost1372/SettingsUI/blob/57b2b8e147407974646cfa6294754877bfcc2398/src/SettingsUI/Tools/Helpers/ThemeHelper.cs#L83-L99

0reactions
github-actions[bot]commented, Jul 28, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found