2011-10-13 1 views
3

wpf의 passwordbox가 Validation.ErrorTemplate을 사용할 수 없다는 것을 알았습니다. 어쨌든 나는 사용자에게 뭔가 잘못되었음을 보여줘야합니다. 뭔가 잘못되면AttachedProperty가있는 PasswordBox의 ErrorTemplate

내 PasswordBox의는 그것이 PasswordBox의의 기본 errortemplate (빨간색 테두리)처럼 같은 스타일을받을 수 있나요이

같은 구속력이있다?

내가 다른 컨트롤

<Style x:Key="baseControlStyle"> 
    <Setter Property="Control.FontFamily" Value="Verdana" /> 
    <Setter Property="Control.FontSize" Value="12" /> 
    <Setter Property="ToolTipService.ShowOnDisabled" Value="True" /> 

    <Setter Property="Validation.ErrorTemplate" > 
     <Setter.Value> 
      <ControlTemplate> 
       <DockPanel LastChildFill="True"> 
        <Image x:Name="Bild" 
          DockPanel.Dock="Right" 
          Source="../Resources/Nein.ico" 
          Margin="-5 0 0 0" 
          MaxHeight="16" 
          MaxWidth="16" 
          VerticalAlignment="Center" 
          ToolTip="{Binding ElementName=myControl, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"> 
        </Image> 
        <Border BorderBrush="Red" BorderThickness="1" CornerRadius="2"> 
         <AdornedElementPlaceholder x:Name="myControl" /> 
        </Border> 
       </DockPanel> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Style.Triggers> 
     <Trigger Property="Validation.HasError" Value="true"> 
      <Setter Property="Control.ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

감사

를 사용하여 내 ErrorTemplate입니다

답변

2

하나의 솔루션은 PasswordBox 아래 실제 TextBox을 넣어 너무 PasswordPropText 속성을 결합하여 제공하는 것 TextBox ErrorTemplate :

<Grid> 
    <TextBox Template="{x:Null}" Style="{StaticResource baseControlStyle}" Text="{Binding PasswordProp, Mode=TwoWay}" />  
    <PasswordBox Name="Password" local:PasswordHelper.Text="{Binding PasswordProp, Mode=TwoWay}" /> 
</Grid> 

ErrorTemplate의 컨트롤이 adorner 레이어에 배치되므로 오류 템플릿은 위의 위에 표시되며 TextBox는 PasswordBox 아래에 있지만 PasswordBox 이벤트가 표시됩니다.

controltemplate을 null으로 설정했습니다. 보이는 것이 아니기 때문에 렌더링 할 필요가 없습니다.