2010-07-27 35 views
0

我试图改变文本框的样式。到现在为止,我已经做我的文本框显示了它的边界与此代码正确的asterisc:在WPF中使用IDataErrorInfo设置文本框的样式

<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> 

,但我想我的文本框上右上角红色三角形显示。我怎么能在我的文本框中获得这种风格?

谢谢。

回答

3

我已经做了我想要的东西,它就像这样:

<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> 
相关问题