Hi all,
I am using the standard WPF theme Aero.NormalColor.xaml. And it works very well. However for the whole application, I would like to override the Foreground color of textboxes to red.
My first try is that
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/PresentationFramework.Aero, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="Red" />
</Style>
</ResourceDictionary>
</Application.Resources>
Well... all foreground color of textboxes become red. However all textboxes lose the theme style. Yes, I know I should add "BasedOn". My second try is add "BasedOn" in the style tag.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/PresentationFramework.Aero, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="Red" />
</Style>
</ResourceDictionary>
</Application.Resources>
Exception is thrown. Same as this http://stackoverflow.com/questions/927251/wpf-extend-themes-style-stackoverflowexception
Eventually, I achieve my goal by this.
In App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/PresentationFramework.Aero, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
And in all windows and user control, I had to explicitly set
<UserControl.Resources>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="Red" />
</Style>
</UserControl.Resources>
The above code is copy and paste for many times and it is not easy to maintain. Does anyone know how to achieve my goal by just set foreground to red by ONE TIME?
Thanks!!