2010-07-27 62 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> 
相關問題