How to override system theme with custom theme?

WPF Studio, Themes, and Shared Library for WPF Forum

The latest build of this product (v21.1.3) was released 3 months ago, which was before this thread was created.
Posted 3 months ago by Michael Janulaitis - Corner Bowl Software
Version: 21.1.3
Avatar

I have written the following code which for some reason wants me to override the BaseBlueColor even though ThemeManager.CurrentTheme is null.  I am not sure why the BaseBlueColor is the one I have to manipulate however once I set that value in the code below the Actipro Controls properly show their colors.  First question is why do we need to use that value?  Second question, the native controls always use the native Windows Settings which I do not want to have anything to do with.  I have tried setting ThemeManager.AreNativeThemesEnabled to both true and false with no luck.  How can I get the native controls to use my custom color?

ThemeManager.BeginUpdate();
try
{                    
    ThemeManager.RegisterThemeDefinition(new ThemeDefinition("Custom")
    {
        BaseColorBlue = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(color700String)
    });

                    
    ThemeManager.AreNativeThemesEnabled = true;
    ThemeManager.CurrentTheme = "Custom";
}
finally
{
    ThemeManager.EndUpdate();
}

If I use the following code the Menu Bar works as expected however the highlight in TextBox does not use my color nor does the ComboBox use my color:

ThemeManager.RegisterThemeDefinition(new ThemeDefinition("Custom")
{
    ColorPaletteKind = ColorPaletteKind.Office,
    BaseColorBlue = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(color700String)
});

[Modified 3 months ago]

Comments (9)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm sorry but I'm not quite sure what problem you are seeing if you don't set BaseColorBlue.  We have never had to set that property to anything other than the default to have themes working, unless of course you want a different shade of blue in your theme.  Are you sure you are seeing an issue with that, and can you tell us how to reproduce it?

If you have ThemeManager.AreNativeThemesEnabled set to true, it apply our themed templates for native controls.  You will see things like buttons and ComboBox highlights use the colors based on the color family described by the ThemeDefinition.PrimaryAccentColorFamilyName property.  That PrimaryAccentColorFamilyName is Blue by default.  So if you set the BaseColorBlue to a Red color (just for testing), you should see the native controls like buttons shift to that color for highlight effects.

As for the TextBox, are you referring to the selection background?  It appears we are not currently setting the TextBox.SelectionBrush property in our style.


Actipro Software Support

Posted 3 months ago by Michael Janulaitis - Corner Bowl Software
Avatar

I just searched the help and do not see any reference to PrimaryAccentColorFamilyName.  The following topic displays in the index but then errors when I click on it:  

file:///C:/Program%20Files%20(x86)/Actipro%20Software/WPF-Controls/v21.1.1/Documentation/api/api/ActiproSoftware.Windows.Themes.Generation.ThemeDefinition.html

The only way I am able to set the colors is by setting the BaseBlueColor.  That works for my array of Material Design colors.

I am running version 21.1

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

This is the ThemeDefinition.PrimaryAccentColorFamilyName property I mentioned.  There was an API documentation link issue in the local documentation (not online docs) in older builds but I believe we fixed it since then in newer ones.

In our theme system, we support color families like "Blue", "Green", etc. For each family, there is a corresponding base color upon which other colors are derived (lighter, darker, etc). The "Blue" color family is the default PrimaryAccentColor, so that is why changing the ThemeDefinition.BaseColorBlue property impacts the main colors used by the theme, unless you change PrimaryAccentColorFamilyName to another color family.

If you haven't already seen it, you can use our Theme Designer app to work with all the ThemeDefinition properties and see how they affect things.


Actipro Software Support

Posted 3 months ago by Michael Janulaitis - Corner Bowl Software
Avatar

Thanks I see the property now. Since I am defining my own colors is sounds like I can simply set the blue base color since I am not using the ActiPro colors but instead Material Design colors.  Is this the case?  

Next, I do not see any of the colors changing in the ComboBox, DataGrid or Context Menus (when a template is applied so icons and seperators can be displayed with view models rather than code behind).  I have already overridden the DataGrid manully so that's no longer an issue for me.  The combobox is the difficult one and would be great to be updated by the theme.

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

You could set BaseColorBlue to make sure everything is relatively close to your Material Design colors.  If you set one of the base color values to about a 600 level color of a Material Design color shade, the generated color ramp should be relatively close to the Material Design palette.

For ComboBox, you should see the button in the theme colors.  Do you see that or are you referring to the text selection background?  We are not currently setting the TextBox.SelectionBrush there or in the TextBox style either, so perhaps we need to look into adding that to the themes?

For DataGrid and ComboBox, I see those as themed when I look in the Theme Designer app's sample UI.  It could be that you are overriding Styles but not basing your Style overrides on ours that support theming? 

This topic lists the style keys for native WPF Controls.  So for instance a custom MenuItem Style would need:

BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.MenuItemStyleKey}}"

We theme the Microsoft DataGrid via an open source assembly and you can find our default Styles in this GitHub repo file.


Actipro Software Support

Posted 3 months ago by Michael Janulaitis - Corner Bowl Software
Avatar

So I just learned the Microsoft Datagrid is unusable with a few thousand virtualized rows when it's grouped. As soon as I remove the theming my control is fast again.  I would like to bail on all the theming except the color.  Is there a way to keep the standard theming but change the color, otherwise I will be forced to remove the theming since my program has to fast no matter the cost?  Can the theming be disabled for the DataGrid?  I already handle all the colors myself.

[Modified 3 months ago]

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Often with complex controls like DataGrid and its parts (rows, columns, etc.), you must theme them with new templates to change their colors.

Can you put together a new simple sample project that shows the performance issue you are describing?  Place a regular DataGrid on the left side of a Window and another themed one on the right side so they can be compared side-by-side.  Then send that to our support address, referencing this thread and we'll try and narrow down what's causing it.  Be sure to exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Posted 3 months ago by Michael Janulaitis - Corner Bowl Software
Avatar

Ok so while I was creating the sample I went back to my production app and learned the issue arises only when the Expander is not overridden.  I had acually just finished applying my own Expander template when you responsed to my above comment.  I have created a the sample and am sending it now.

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Thanks for sending the sample.  It was helpful in locating the problem.  We have made some code updates for the next major version 22.1 that will resolve the issue in our themed Expander template. 

If you wanted to keep Actipro themes active until then but wanted to work around the issue, you'd have to create a custom implicit Style for Expander and put that in your Application.Resources, and make sure it's Template didn't include our AnimatedExpanderDecorator class.  That class is where the issue was originating and is resolved for v22.1.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.