Reputation: 447
I am using WPF. Please look at comment related to Foreground in code. When the textbox gets focused, the font should be changed to white but it is not working. Why?
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="bg" BorderBrush="#FFDCDCC9" Background="#FFDCDCC9" BorderThickness="1">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="bg" Value="#FFEC94C0"/>
<Setter Property="Background" TargetName="bg" Value="#FFEC94C0"/>
<Setter Property="BorderThickness" TargetName="bg" Value="2"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
<Trigger Property="IsFocused" Value="True" >
<Setter Property="BorderBrush" TargetName="bg" Value="#FFB5266E"/>
<Setter Property="Background" TargetName="bg" Value="#FFEC94C0"/>
<!-- foreground is invalid -->
<Setter Property="Foreground" TargetName="bg" Value="white"/>
<Setter Property="BorderThickness" TargetName="bg" Value="2"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Upvotes: 2
Views: 1846
Reputation: 329
Border does not have a foreground. Remove TargetName from the equation... I believe it will work then. It should look like below (also if this is a resource itt will need a key). This worked fine my end.
<ControlTemplate x:Key="a" TargetType="{x:Type TextBox}">
<Border x:Name="bg" BorderBrush="#FFDCDCC9" Background="#FFDCDCC9" BorderThickness="1">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="bg" Value="#FFEC94C0"/>
<Setter Property="Background" TargetName="bg" Value="#FFEC94C0"/>
<Setter Property="BorderThickness" TargetName="bg" Value="2"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
<Trigger Property="IsFocused" Value="True" >
<Setter Property="BorderBrush" TargetName="bg" Value="#FFB5266E"/>
<Setter Property="Background" TargetName="bg" Value="#FFEC94C0"/>
<!-- foreground is invalid -->
<Setter Property="Foreground" Value="white"/>
<Setter Property="BorderThickness" TargetName="bg" Value="2"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Upvotes: 2