I want to change the background color of a disable numerictextbox. But somehow I can't get it done...I looked at the included themes and got out the code that refers to the numeric textbox. I found two blocks of code. The style "NumericTextBox" and the control template "TextBoxTemplate" (see below). Somehow as soon as I refer to the "TextBoxTemplate" I get an error stating that :
Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.FrameworkTemplate'.
I have no idea how to solve this... any clues ? Did I extract enough code ? Is there an easier way to change the background of my disabled control ?
Thanks !
<Style TargetType="{x:Type local:NumericTextBox}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Background" Value="{StaticResource TextBoxBackground}" />
<Setter Property="Foreground" Value="{StaticResource TextBoxForeground}" />
<Setter Property="BorderBrush" Value="{StaticResource {x:Static local:FilteringTextBoxBase.BorderBrushKey}}" />
<Setter Property="Focusable" Value="False" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NumericTextBox}">
<TextBox x:Name="PART_TextBox"
HorizontalScrollBarVisibility="Disabled"
AcceptsReturn="False"
AutoWordSelection="False"
IsReadOnly="{TemplateBinding IsReadOnly}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
TextAlignment="{TemplateBinding TextAlignment}"
>
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type local:NumericTextBox}}}" />
<Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type local:NumericTextBox}}}" />
<Setter Property="BorderBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType={x:Type local:NumericTextBox}}}" />
<Setter Property="BorderThickness" Value="{Binding BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type local:NumericTextBox}}}" />
<Setter Property="Template" Value="{StaticResource TextBoxTemplate}" />
</Style>
</TextBox.Style>
</TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}">
<Grid>
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<DockPanel VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<ScrollViewer Margin="1" x:Name="PART_ContentHost" Height="{TemplateBinding Height}" />
</DockPanel>
</Border>
<Border Name="DisabledBorder" Style="{StaticResource DisabledBorderStyle}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="DisabledBorder" Property="Visibility" Value="Visible" />
<Setter Property="Foreground" Value="{StaticResource DisabledForeground}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>