Change the textbox foregroundcolor when specific theme is enabled

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 7 years ago by Andreas Gruber
Version: 16.1.0635

Hello members of the Actipro community!

I am using different themes in a customer application. The application has many views with textboxes.When a certain theme is activated, in this case "MetroDark", I have problems with the contrast of the textbox background (black) and the foreground color. Depending on the environmental lighting (sun), the content of the textboxes could be hard to read. So I should change the text color to white or something else so that the contrast becomes better.

The customer is advised to restart the application if the theme is changed.

I tried the following code to change the forground property of the textbox style when MetroDark is activated 

ThemeManager.CurrentTheme = ThemeName.MetroDark.ToString();

Style style = newStyle();
style.TargetType = typeof(TextBox);
Style currentStyle = (Style)Application.Current.FindResource(typeof(TextBox));

foreach (var item in currentStyle.Setters)
  if (((Setter)item).Property != TextBox.ForegroundProperty)
   // add all other settings to the new style, except the foreground property

style.Setters.Add(newSetter(TextBox.ForegroundProperty, newSolidColorBrush(Colors.White)));

// remove the current style
if (Application.Current.Resources[typeof(TextBox)] != null)

// add the new style
Application.Current.Resources.Add(typeof(TextBox), style);

While checking the code, i have seen that the value of the foreground setter references the "ActiproSoftware.Windows.Themes.AssetResourceKeys.ToolBarEditForegroundNormalBrushKey".
As the code does not do anything, how or where can I change the color of the ToolBarEditForegourndNormalBrushKey resource in my code?

Thank you for your help.

Comments (2)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Andreas,

As long as you are using MetroDark theme and have our native control themes enabled, TextBox controls should be using white foreground and be plenty visible.  Can you point to a specific usage example in our Sample Browser where you don't see the contrast looking good?  A sample I just reviewed was the "Themes / Native Control Themes" one.

Actipro Software Support

Posted 7 years ago by Andreas Gruber


I have to appologize about contacting you in this issue. After your post i checked the sample browse and you are right that the color is white after your theme is applied.

I further investigated the code and found out, that the theme for the microsoft controls is reset by a second library. After deactivating the styling of the default controls in the other library the actipro styling is shown.

Thank you for your help.

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.