2010-07-27 4 views
0

스타일을 텍스트 상자로 변경하려고합니다.WPF에서 IDataErrorInfo를 사용하여 TextBox 스타일 지정

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

하지만 내 텍스트 상자 오른쪽 상단 모서리에 빨간색 삼각형 표시하고 싶습니다 : 지금까지, 나는 나의 텍스트 상자에이 코드와의 국경의 오른쪽에 asterisc을 보여주고 있음을 만들었습니다. 내 텍스트 상자에서 어떻게이 스타일을 얻을 수 있습니까?

감사합니다.

은 이미 내가 원하는 것을했을

답변

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> 
관련 문제