AdornerDecorator and tab stop issues

Posted by Trev on Stack Overflow See other posts from Stack Overflow or by Trev
Published on 2008-12-10T00:20:33Z Indexed on 2010/05/24 23:41 UTC
Read the original article Hit count: 282

Hi,

I am using IDataErrorInfo to validate and indicate errors in my text boxes. I am finding I have to tab once for the text box and once for the adornerdecorator.

I have an error template:

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

a textbox template:

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

and declare a text box like this:

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

If the adorner is round one text box as above then I tab once to leave the text box and once to leave the 'adornment' (it seems) If I have the adorner around a stackpanel of text boxes then I tab once each for the text boxes then have to go back through all the 'adornments' in turn. When tabbing through the adornments the focus goes on the red border defined in the control template..

any ideas?

thanks

© Stack Overflow or respective owner

Related posts about wpf

Related posts about validation