I script-kiddied this code to show helper text in a field before the field is populated by the user (also plan on using some modification of it to show the validation error if one occurs), but the trigger isn’t, well, triggering. What’s wrong with this code?
xaml:
<TextBox x:Name="firstName" Validation.Error="Text_ValidationError"
Text="{Binding UpdateSourceTrigger=LostFocus, Path=firstName, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Margin="30,12,50,245">
<TextBox.Style>
<Style TargetType="TextBox" >
<Style.Triggers>
<DataTrigger Binding="{Binding Path=firstName}" Value="">
<Setter Property="Background">
<Setter.Value>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<TextBlock Text="First name" />
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
Don’t use a
DataTriggerfor this, it’s not necessary (the binding might be broken, in fact that is the only thing that i can think of that might cause this not to work), use a normalTrigger:Tested this, it works. This also has the advantage that the background disappears immediately when the user starts typing rather than when the focus on the control is lost and the source string is updated.