Inherit from default TextBox Style

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 7 years ago by Stefan
Version: 11.2.0553
Avatar

Hi, 

I am trying to add some styling to a textbox, at the moment I use:

<Style TargetType="TextBox" BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.TextBoxBaseStyleKey}}">

This works fine, I tried to use BasedOn="{StaticResource {x:Type TextBox}}" but this does not work for me? just trying to find an easier way to inherit the current styles.

Comments (2)

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

Hi Stefan,

When accessing the Style via the SharedResourceKey you are guaranteed to get the correct style. WPF will even load up the appropriate XAML files from our assembly, if they have not been loaded yet.

When using the control type, it would only work if you have ThemeManager.AreNativeThemesEnabled set to true. As this loads up an implicit Style for TextBox based on our SharedResourceKey. If you don't set that to true, then you may be getting the default Style for the TextBox (which is defined by WPF).

In any event, it is generally better to base your styles on our SharedResourceKeys. But there may be instances where you want to access them by control type, when you are basing a custom style on another custom style.


Actipro Software Support

Posted 7 years ago by Stefan
Avatar

I actually do have AreNativeThemesEnabled set to true, I might keep going on with the implicit style anyway as it is working fine.

 

Thanks for your help.

The latest build of this product (v2019.1 build 0681) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.