Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Binding FontSize of TextBlock in Validation.ErrorTemplate
  2. <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
  3.     <Setter Property="Validation.ErrorTemplate">
  4.         <Setter.Value>
  5.             <ControlTemplate>
  6.                 <DockPanel LastChildFill="True">
  7.                     <TextBlock Text="!" DockPanel.Dock="Right"
  8.                                FontSize="{TemplateBinding TextBox.FontSize}"
  9.                                Foreground="Red"/>
  10.                     <AdornedElementPlaceholder  Name="adornerPlaceholder" />
  11.                 </DockPanel>
  12.             </ControlTemplate>
  13.         </Setter.Value>
  14.     </Setter>
  15. </Style>
  16.        
  17. <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
  18. <Setter Property="Validation.ErrorTemplate">
  19.     <Setter.Value>
  20.         <ControlTemplate>
  21.             <DockPanel LastChildFill="True">
  22.                 <TextBlock Text="!" DockPanel.Dock="Right"
  23.                            FontSize="{Binding ElementName=adornerPlaceholder, Path=AdornedElement.FontSize}"
  24.                            Foreground="Red"/>
  25.                 <AdornedElementPlaceholder  Name="adornerPlaceholder" />
  26.             </DockPanel>
  27.         </ControlTemplate>
  28.     </Setter.Value>
  29. </Setter>
  30. </Style>
  31.        
  32. <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
  33.     <Setter Property="Validation.ErrorTemplate">
  34.         <Setter.Value>
  35.             <ControlTemplate>
  36.                 <DockPanel LastChildFill="True">
  37.                     <Viewbox DockPanel.Dock="Right"
  38.                         Height="{Binding ElementName=adornerPlaceholder, Path=ActualHeight}"
  39.                         Stretch="Uniform"
  40.                         Margin="5 0">
  41.                         <TextBlock Text="!" Foreground="Red" />
  42.                     </Viewbox>
  43.                     <AdornedElementPlaceholder Name="adornerPlaceholder" />
  44.                 </DockPanel>
  45.             </ControlTemplate>
  46.         </Setter.Value>
  47.     </Setter>
  48. </Style>