This project has moved. For the latest updates, please go here.

Style from ResourceDictionary?

Apr 5, 2012 at 8:48 AM

Hello,

I've got an understanding issue: I cannot reconstruct how the control (e. g. the ColorPicker) gets his Style from the ResourceDictionary in Generic.xaml.

Where is the connection? I couldn't find it in the code.

Thanks in advance,

ThermDev

Coordinator
Apr 5, 2012 at 3:45 PM

Hi,

 

The controls of the Extended WPF Toolkit are styled via implicit styles.  You will not find any line of code that explicitly set this style.  This is done "magically" by the framework.  To find out more about how it works, you may read this article.

 

To give you an hint, the ColorPicker sets its DefaultStyleKey to the type ColorPicker.  This means that the default style that is going to be used is the one that has a TargetType of type ColorPicker with no x:Key set explicitly.

 

In other words, it will look for:

<Style TargetType="{x:Type ColorPicker}">
  ...
</Style>
Nov 16, 2012 at 4:28 PM

I'm trying to style a WatermarkTextBox so assuming it's based on TextBox, correct?

<Style TargetType="{x:Type TextBox}">
	<Setter Property="Foreground" Value="Gray" />
	<Setter Property="FontFamily"  Value="Calibri" />
	<Setter Property="FontStyle" Value="Normal" />
	<Setter Property="FontSize" Value="14" />
</Style>
This does not change on the XAML editor preview in VS2010 or when run.

Nov 16, 2012 at 7:04 PM

The target type need to be "{x:Type xctk:WatermarkTextBox}" to make it work. This will only apply to pure TextBox or TextBox derived classes that did not override the "DefaultStyleKey" property. Which is not the case for the WatermarkTextBox.