ErrorTemplate.xaml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:controls="clr-namespace:FWindSoft.Wpf.Controls"
  4. xmlns:wpf="clr-namespace:FWindSoft.Wpf">
  5. <ControlTemplate x:Key="ErrorTemplate">
  6. <Border BorderBrush="Red" BorderThickness="1">
  7. <AdornedElementPlaceholder/>
  8. </Border>
  9. </ControlTemplate>
  10. <Style x:Key="{x:Static wpf:ResourceKeys.ErrorTemplateKey}" TargetType="Control">
  11. <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}">
  12. </Setter>
  13. <Style.Triggers>
  14. <Trigger Property="Validation.HasError" Value="True">
  15. <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
  16. </Trigger>
  17. </Style.Triggers>
  18. </Style>
  19. <ControlTemplate x:Key="ErrorTemplate2">
  20. <DockPanel LastChildFill="true">
  21. <Border Background="Red" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="10"
  22. ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
  23. <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white">
  24. </TextBlock>
  25. </Border>
  26. <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" >
  27. <Border BorderBrush="Red" BorderThickness="1" />
  28. </AdornedElementPlaceholder>
  29. </DockPanel>
  30. </ControlTemplate>
  31. <Style x:Key="{x:Static wpf:ResourceKeys.ErrorTemplateKey2}" TargetType="Control" >
  32. <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}">
  33. </Setter>
  34. <Style.Triggers>
  35. <Trigger Property="Validation.HasError" Value="True">
  36. <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
  37. </Trigger>
  38. </Style.Triggers>
  39. </Style>
  40. <ControlTemplate x:Key="{x:Static wpf:ResourceKeys.EmptyErrorTemplateKey}">
  41. <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" >
  42. </AdornedElementPlaceholder>
  43. </ControlTemplate>
  44. </ResourceDictionary>