code_junkie

How do you implement default text for a search box in WPF?

Nov 13th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <TextBox.Style>
  2. <Style TargetType="TextBox">
  3. <Style.Triggers>
  4. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="">
  5. <Setter Property="Background">
  6. <Setter.Value>
  7. <VisualBrush Stretch="None">
  8. <VisualBrush.Visual>
  9. <TextBlock Text="Enter value" Foreground="Gray"/>
  10. </VisualBrush.Visual>
  11. </VisualBrush>
  12. </Setter.Value>
  13. </Setter>
  14. </DataTrigger>
  15. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="{x:Null}">
  16. <Setter Property="Background">
  17. <Setter.Value>
  18. <VisualBrush Stretch="None">
  19. <VisualBrush.Visual>
  20. <TextBlock Text="Enter value" Foreground="Gray"/>
  21. </VisualBrush.Visual>
  22. </VisualBrush>
  23. </Setter.Value>
  24. </Setter>
  25. </DataTrigger>
  26. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsFocused}" Value="True">
  27. <Setter Property="Background">
  28. <Setter.Value>
  29. <VisualBrush Stretch="None">
  30. </VisualBrush>
  31. </Setter.Value>
  32. </Setter>
  33. </DataTrigger>
  34. </Style.Triggers>
  35. </Style>
  36. </TextBox.Style>
Add Comment
Please, Sign In to add comment