So, I styled my TextBoxes in an app that I’m working on, and all of a sudden I can’t see any text that I’ve bound to my TextBoxes. I feel like I’m missing some kind of ContentPresenter. Well anyway, here is the styling.
<Style TargetType="{x:Type TextBox}">
<Setter Property="Height" Value="26"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Value="#FF2F2F2F" Property="Background"/>
<Setter Value="White" Property="Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here is how my TextBoxes are set up
<TextBox Grid.Row="2" Grid.Column="5" BorderThickness="1" Text="{Binding VariableName}">
Any thoughts?
Your hunch is right, you need to have a template part with the name
PART_ContentHostinside yourControlTemplate:This is because the
ControlTemplatefor aTextBoxrequires a part with the namePART_ContentHost. You can view theControlTemplateexamples for the built-in controls to find out what named template parts are required and what each part must be able to do in order to retain normal functionality.