2008-12-10 18 views
3

我正在使用IDataErrorInfo來驗證並在我的文本框中指出錯誤。我發現我必須爲文本框選擇一次,併爲adornerdecorator選擇一次。AdornerDecorator和製表符問題

我有一個錯誤的模板:

<ControlTemplate x:Key="ErrorTemplate"> 
     <StackPanel KeyboardNavigation.IsTabStop="False" > 
     <Border KeyboardNavigation.IsTabStop="False" BorderBrush="Red" BorderThickness="1" Padding="2" CornerRadius="2"> 
      <AdornedElementPlaceholder KeyboardNavigation.IsTabStop="False" /> 
     </Border> 
     </StackPanel>     
    </ControlTemplate> 

一個文本框模板:

<Style x:Key="TextBoxInError" TargetType="{x:Type TextBox}"> 
     <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> 
     <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
     <Setter Property="Margin" Value="0,5,0,5"/> 
     <Setter Property="AllowDrop" Value="true"/> 
     <Setter Property="HorizontalContentAlignment" Value="left"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TextBox}"> 
        <Grid KeyboardNavigation.IsTabStop="False" > 
         <Border KeyboardNavigation.IsTabStop="False" x:Name="Border" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" Padding="2" CornerRadius="2"> 
          <ScrollViewer IsTabStop="False" Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleScrollViewer}" Background="{TemplateBinding Background}"/> 
         </Border> 
        </Grid> 
        <ControlTemplate.Triggers> 
         <Trigger Property="Validation.HasError" Value="true"> 
          <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/> 
         </Trigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Foreground" Value="Gray"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

,並宣佈這樣一個文本框中:

<AdornerDecorator KeyboardNavigation.IsTabStop="False" > 
<TextBox Margin="5,5,5,3" x:Name="txtName" IsEnabled="{Binding EditMode}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" 
Text="{Binding ApplicationName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
Height="25" MaxLength="50" MaxLines="1" Style="{StaticResource TextBoxInError}"/> 
</AdornerDecorator> 

如果裝飾器是圓的一個文本框如上,然後我選擇一次離開文本框,一次離開'裝飾'(看起來)如果我有裝飾者圍繞一個文本框的堆疊面板,然後我爲每個文本框選擇一次,然後必須依次返回所有'裝飾物'。當穿過裝飾品時,焦點集中在控制模板中定義的紅色邊框上。

任何想法?

感謝

回答