How can I find the brushes used for the native toolbar theme?

WPF Studio, Themes, and Shared Library for WPF Forum

The latest build of this product (v2019.1 build 0685) was released 4 months ago, which was before this thread was created.
Posted 6 days ago by Josh Holdaway
Version: 17.2.0685
Avatar

How can I find the brushes used for the native toolbar theme?

I'm looking to override/change some of the colors from the default MetroDark theme to match a host application's dark theme.

Thanks in advance!.

[Modified 6 days ago]

Comments (7)

Posted 6 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

There is a Theme Browser utility in the Sample Browser app.  You can access it from the Tools menu.  If you type in "ToolBar" in the filter, you can see all the brushes generally used in toolbars.

We try to name the brush keys pretty well for their intended usage.  If you need more information on exact usage, you could get our default styles/templates and search through those to see where and how each one is used.  Licensed customers can have access to the default styles/templates.


Actipro Software Support

Posted 5 days ago by Josh Holdaway
Avatar

Can you provide an example of how I would override certain colors?

For example, I want to change the hover background color of the native toolbar button.

I have tried: <SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.ToolBarButtonBackgroundHoverBrushKey}" Color="Red" />

But it doesn't work.  This is a plugin to autocad and I'm adding a CustomDarkTheme.xaml to Application.Current.Resources.

[Modified 5 days ago]

Posted 5 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Josh,

Please see the "Themes / Reusable Assets" topic in the documentation that comes with the product.  There is a "Customizing Theme Assets" section in there with an example.

Also make sure you have set ThemeManager.AreNativeThemesEnabled to true in your application OnStartup code so that our themed styles will be applied to native WPF controls.

What you are doing generally looks right.  Perhaps make sure you inject your resource dictionary into the Application.Resources before any other UI is ever loaded and ensure that all references to the Brush are made with DynamicResource.

If you still have problems, try putting your override right in Application.Resources directly and see if it makes a difference.  If that still doesn't work, I wonder if it's something with the interop with AutoCad that you mentioned that isn't letting the update propagate properly.  Or it could be a specific Style is being applied to that ToolBar or button that is blocking our implicit Style from being applied.


Actipro Software Support

Posted 5 days ago by Josh
Avatar

So to more easily test this, I'm trying to set the background of the toolbar.  (easiest to see red :-)

I have downloaded the styles from the downloads page for my purchased products, and I can see

		<Setter Property="Background" Value="{DynamicResource {x:Static themes:AssetResourceKeys.ToolBarHorizontalBackgroundNormalBrushKey}}" />

Since this is a plugin to autocad, I dont have an application.  And in the startup of the plugin, I'm doing the following:

			ActiproSoftware.Windows.Themes.ThemeManager.BeginUpdate();
			ActiproSoftware.Windows.Themes.ThemeManager.CurrentTheme = "System";
			ActiproSoftware.Windows.Themes.SharedThemeCatalogRegistrar.Register();
			ActiproSoftware.Windows.Themes.DockingThemeCatalogRegistrar.Register();
			ActiproSoftware.Windows.Themes.RibbonThemeCatalogRegistrar.Register();
			ActiproSoftware.Windows.Themes.ThemeManager.AreNativeThemesEnabled = true;
			ActiproSoftware.Windows.Themes.ThemeManager.EndUpdate();

I then have a custom Light and Dark resource dictionary I'm switching out to support Autocad's light and dark theme.    When I set the theme of actipro to:

ActiproSoftware.Windows.Themes.ThemeManager.CurrentTheme = "System";

or

ActiproSoftware.Windows.Themes.ThemeManager.CurrentTheme = "MetroDark";

I can see the toolbar change its color correctly.  But any overrides, never work.

I then have a toolbar inside a UserControl, and inside the UserControl's resource dictionary, I place the following to test:

	<SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.ToolBarHorizontalBackgroundNormalBrushKey}" Color="Red" />

It doesn't show red.

I'm also placing my custom Light and dark resource dictionaries like so:

var theme = new ResourceDictionary
{
    Source = uri
};
				Application.Current.Resources.MergedDictionaries.Add(theme);

Thoughts?

[Modified 5 days ago]

Posted 5 days ago by Josh
Avatar

Okay, I think I found my problem.

We had the following:

	<Style TargetType="{x:Type ToolBar}" BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.ToolBarStyleKey}}">
		<Setter Property="themes:ThemeManager.Theme" Value="{Binding Source={x:Static core:Theme.Instance}, Path=NativeToolbarTheme}"/>
	</Style>

And for some odd reason, this was forcing the actipro colors and not using the overrides.

Posted 5 days ago by Josh
Avatar

However, when I remove that binding to our custom theme class, which btw.. is just binding to a string thats either "System" or "MetroDark", the theme doesn't get changed, but the overrides work.

Am I missing something?

Our custom theme class is calling the following:

ActiproSoftware.Windows.Themes.ThemeManager.CurrentTheme = "MetroDark";

Is this enough to get the UI to update on the fly?  What should I be doing?

[Modified 5 days ago]

Answer - Posted 5 days ago by Josh
Avatar

Okay sorry for all the quick replies.  It seems I have gotten it to work.

					Application.Current.Resources.MergedDictionaries.Clear();

					// inject actipro's native themes
					ActiproSoftware.Windows.Themes.ThemeManager.BeginUpdate();
					ActiproSoftware.Windows.Themes.SharedThemeCatalogRegistrar.Register();
					ActiproSoftware.Windows.Themes.DockingThemeCatalogRegistrar.Register();
					ActiproSoftware.Windows.Themes.RibbonThemeCatalogRegistrar.Register();
					ActiproSoftware.Windows.Themes.ThemeManager.AreNativeThemesEnabled = true;
					ActiproSoftware.Windows.Themes.ThemeManager.EndUpdate();

The idea is this, when changing the theme within Autocad, i wipe out the application resources which actipro seems to be injecting.  I then rebuild them, and finally I add my custom one afterwards, and everything seems to be working just fine.

Thanks!

Add Comment

Please log in to a validated account to post comments.