Remove theme from User Control ( and all child controls )

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 1 month ago by John Dunn
Version: 21.1.1
Avatar

Is there a way to remove automatic theming from a specific user control ? We have a portion of our application which is already customed themed and would like to remove the automatic theming for the native controls.

Comments (6)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

WPF themes (which are basically resources) all inherit down from Application.Resources to element.Resources and down the visual tree.  Unfortunately there isn't a way that we are aware of in WPF to turn off resource inheritance for a particular UserControl.  The only thing you can do is add resources at the UserControl level that override inherited ones, or not use Application.Resources or any ancestor element.Resources.


Actipro Software Support

Posted 1 month ago by John Dunn
Avatar

It there any way to get the list of all the keys with their brushes for a given theme? It looks like I can add a bunch of entries like

  <SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.BulletBackgroundCheckedHoverBrushKey}" Color="White" />
  <SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.BulletBackgroundCheckedNormalBrushKey}" Color="AliceBlue" />

but it's going to be error prone to make sure I catch everything. 

Another approach that might work - can I assign a different theme to a particular subtree of controls?

Posted 1 month ago by John Dunn
Avatar

For some context - in my case there I have a UserControl which looks fine in light mode but because of a bunch of styling doesn't look good in dark mode. For now if I could just force the UserControl to use light mode even when the rest of the application was in dark mode that'd probably work fine.

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

The Theme Designer app has a Resource Browser tab that allows you to see all of the hundreds of resources in a theme and their values.

But it sounds like the best approach for your scenario is to set a light theme on that UserControl.  We do have a feature to do that but it should be used sparingly.  Please see the related documentation.


Actipro Software Support

Posted 1 month ago by John Dunn
Avatar

Unfortunatly that didn't seem to work. The main control was styled correctly but any dialogs it opened would still be based on the main application style. So I think remapping the resource names is the only approach that will work for me.

One thing that would be nice would be an easy way to get the #RRGGBB values from the Resource Browser. This isn't the only time I've wanted to do that - I've also needed to match theme colors in areas that don't use the direct resources. Maybe adding a 'Copy Color Value' to the right click menu? Right now I'm resorting to use the Power Tools color picker but it's not the best workflow.

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

Separate WPF Windows will base themselves on the Application.Resources, so that's likely what's happening with your dialogs.  It's pulling those instead of the ones from your UserControl, since the dialog is a completely separate visual hierarchy.  Are you able to detect when dialogs are opening and update the Window.Resources on them with a light theme?

In regards to the Theme Browser, we will add the "Copy Color Value" context menu item for the next build.


Actipro Software Support

The latest build of this product (v21.1.2) was released 19 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.