2010-07-27 9 views
0

J'essaie de changer de style dans une zone de texte. Maintenant, je l'ai fait que mon champ de saisie montre une asterisc à droite de sa frontière avec ce code:Stylisation d'un TextBox avec IDataErrorInfo dans WPF

<Style TargetType="{x:Type TextBox}"> 
     <Setter Property="Validation.ErrorTemplate"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Grid> 
         <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right" Foreground="Red" FontSize="14pt" FontWeight="Bold" Text="*"></TextBlock> 
         <Border BorderBrush="Red" BorderThickness="1"> 
          <AdornedElementPlaceholder Name="controlWithError"/> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     <Style.Triggers> 
      <Trigger Property="Validation.HasError" Value="true"> 
       <Setter Property="ToolTip" Value="{Binding Path=(Validation.Errors)[0].ErrorContent}"/> 
      </Trigger> 
      </Style.Triggers> 
    </Style> 

Mais je voudrais ma zone de texte affiché avec un triangle rouge sur le coin supérieur droit. Comment pourrais-je obtenir ce style sur ma zone de texte?

Merci.

Répondre

3

Je l'ai déjà fait ce que je voulais, il était comme ça:

<Style TargetType="{x:Type TextBox}"> 
     <Setter Property="Validation.ErrorTemplate"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Grid> 
         <Polygon Points="0,0 10,0 0,10 0,0" HorizontalAlignment="Right" Fill="Red" FlowDirection="RightToLeft"></Polygon> 
         <Border BorderBrush="Red" BorderThickness="1"> 
          <AdornedElementPlaceholder Name="controlWithError" /> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     <Style.Triggers> 
      <Trigger Property="Validation.HasError" Value="true"> 
       <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> 
      </Trigger> 
      </Style.Triggers> 
    </Style>