Guest User

Untitled

a guest
May 28th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Validation Error Templates For UserControl
  2. <UserControl.Resources>
  3. <Style TargetType="{x:Type TextBox}">
  4. <Style.Triggers>
  5. <Trigger Property="Validation.HasError" Value="true" >
  6. <Setter Property="Foreground" Value="Red"/>
  7. <Setter Property="Background" Value="MistyRose"/>
  8. <Setter Property="BorderBrush" Value="Red"/>
  9. <Setter Property="BorderThickness" Value="1.0"/>
  10. <Setter Property="VerticalContentAlignment" Value="Center"/>
  11. <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource
  12. Self},Path=(Validation.Errors)[0].ErrorContent}"/>
  13. </Trigger>
  14. </Style.Triggers>
  15. </Style>
  16. </UserControl.Resources>
  17.  
  18. <TextBox >
  19. <Validation.ErrorTemplate>
  20. <ControlTemplate>
  21. </ControlTemplate>
  22. </Validation.ErrorTemplate>
  23. </TextBox>
  24.  
  25. <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
  26.  
  27. <Setter Property="Template">
  28. <Setter.Value>
  29. <ControlTemplate TargetType="{x:Type TextBoxBase}">
  30. <Border
  31. Name="Border"
  32. CornerRadius="5"
  33. Padding="2"
  34. BorderBrush="{TemplateBinding BorderBrush}"
  35. Background="{TemplateBinding Background}"
  36. BorderThickness="{TemplateBinding BorderThickness}" >
  37. <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
  38. </Border>
  39. <ControlTemplate.Triggers>
  40. <Trigger Property="IsEnabled" Value="False">
  41. <Setter TargetName="Border" Property="Background" Value="LightGray"/>
  42. <Setter TargetName="Border" Property="BorderBrush" Value="Black"/>
  43. <Setter Property="Foreground" Value="Gray"/>
  44. </Trigger>
  45. <Trigger Property="Validation.HasError" Value="true">
  46. <Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ErrorBorderColor}"/>
  47. <Setter Property="Background" TargetName="Border" Value="{DynamicResource ErrorBackgroundColor}"/>
  48. </Trigger>
  49. </ControlTemplate.Triggers>
  50. </ControlTemplate>
  51. </Setter.Value>
  52. </Setter>
Advertisement
Add Comment
Please, Sign In to add comment