AdornerDecorator和制表符停止问题

Tre*_*rev 3 validation wpf xaml adornerdecorator tabstop

我正在使用IDataErrorInfo验证并指出我的文本框中的错误.我发现我有一次Tab文本框,一次用于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>
Run Code Online (Sandbox Code Playgroud)

文本框模板:

<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>
Run Code Online (Sandbox Code Playgroud)

并声明一个这样的文本框:

<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>
Run Code Online (Sandbox Code Playgroud)

如果装饰器是圆的一个文本框的上方,然后我标签一旦离开文本框,一旦离开了"装饰"(似乎)如果我身边的文本框的StackPanel装饰器然后我标签一旦每个文本然后盒子必须依次回顾所有的"装饰品".通过装饰标签时,焦点会出现在控件模板中定义的红色边框上.

有任何想法吗?

谢谢

Nir*_*Nir 6

将其添加到窗口的资源部分:

<Style TargetType="{x:Type Control}">
    <Setter Property="Focusable" Value="False"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看我的博客:http://www.nbdtech.com/blog/archive/2008/05/25/WPF-Problems-with-Keyboard-Focus-When-Using-Validation.aspx