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.

Best way to override colours for controls?

See original GitHub issue

I want to give the buttons a border (in another project that uses the nuget package). How should I override the color key in my own resource dictionary?

For example, in Dark.xaml there is

<m:StaticResource x:Key="ButtonBorderBrush" ResourceKey="SystemControlForegroundTransparentBrush" />

If I want to set this to SystemControlBackgroundBaseMediumHighBrush what is the best way that will still respect the theme settings?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Sylvain2703commented, Nov 26, 2020

Hello,

Is it still possible to override the default resources by taking into account the theme on v0.9.2? As DefaultThemeResources doesn’t exist anymore, I don’t know how to get it works.

In advance, thanks for your help and for this great library!

EDIT: It’s okay, I just found

<ui:ThemeResources>
    <ui:ThemeResources.ThemeDictionaries>
        <ResourceDictionary x:Key="Light" ui:ThemeDictionary.Key="Light">
            <StaticResource x:Key="TextControlBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
            <StaticResource x:Key="TextControlBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumHighBrush" />
        </ResourceDictionary>
        <ResourceDictionary x:Key="Dark" ui:ThemeDictionary.Key="Dark">
            <StaticResource x:Key="TextControlBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
            <StaticResource x:Key="TextControlBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumHighBrush" />
        </ResourceDictionary>
        <ResourceDictionary x:Key="HighContrast" ui:ThemeDictionary.Key="HighContrast">
            <StaticResource x:Key="TextControlBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
            <StaticResource x:Key="TextControlBorderBrushPointerOver" ResourceKey="SystemControlHighlightBaseMediumHighBrush" />
        </ResourceDictionary>
    </ui:ThemeResources.ThemeDictionaries>
</ui:ThemeResources>
1reaction
Kinnaracommented, Oct 29, 2019
  1. Add a theme dictionary inside the <ui:ThemeResources> element in App.xaml:
<ui:ThemeResources>
    <ui:ThemeResources.ThemeDictionaries>
        <ResourceDictionary x:Key="Dark">

        </ResourceDictionary>
    </ui:ThemeResources.ThemeDictionaries>
</ui:ThemeResources>
  1. If you need to reference the built-in resources, merge them first:
<ResourceDictionary x:Key="Dark">
    <ResourceDictionary.MergedDictionaries>
        <ui:DefaultThemeResources Key="Dark" />
    </ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
  1. Redefine the resource you want to override:
<ResourceDictionary x:Key="Dark">
    <ResourceDictionary.MergedDictionaries>
        <ui:DefaultThemeResources Key="Dark" />
    </ResourceDictionary.MergedDictionaries>
    <ui:StaticResource x:Key="ButtonBorderBrush" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
</ResourceDictionary>

Currently this doesn’t seem to take effect at design time, but does work at run time. And usually you’ll need to override the brushes used by other states (such as ButtonBorderBrushPointerOver) as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing colours of Custom Controls - NI Community
I've made a custom control by adding a logo to a standard boolean square button. I want to be able to change the...
Read more >
Cannot override controls foreground colour in wpf
Its effectively ignoring the Foreground setter property. The only way to get this to work as expected is to the do following: <Button...
Read more >
Override Button Color with Theme in UI for WinForms
What's the best way to do this while still retaining the "look" of the theme. The theme currently in use is "Breeze" but...
Read more >
Can I change the color of control panel icons : r/Huawei
If you only want to change the color, select "customize" instead of "apply" on the theme you just downloaded and make sure there's...
Read more >
How to Change the Xbox Button Color on the Elite Series 2 ...
Look at the Color tab to find the color that you'd like to use for your controller. There will be a variety of...
Read more >

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