Question

J'utilise IDataErrorInfo pour valider et indiquer des erreurs dans mes zones de texte. Je trouve que je dois onglet une fois pour la zone de texte et une fois pour le adornerdecorator.

J'ai un modèle d'erreur:

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

un modèle de zone de texte:

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

et déclarer une zone de texte comme ceci:

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

Si le Adorner est rond une zone de texte comme ci-dessus je tab une fois pour quitter la zone de texte et une fois quitter (il semble) la « parure » Si je le Adorner autour d'un StackPanel des zones de texte je onglet une fois par pour les zones de texte doivent alors revenir par tous les « » à son tour des ornements. Quand à travers les tabulant l'accent va ornements à la frontière rouge défini dans le modèle de contrôle ..

idées?

Merci

Était-ce utile?

La solution

Ajoutez ceci à la section des ressources de la fenêtre:

<Style TargetType="{x:Type Control}">
    <Setter Property="Focusable" Value="False"/>
</Style>

Pour plus d'informations regarder mon blog: http://www.nbdtech.com/blog/archive/2008/05/25/WPF-Problems-with-Keyboard-Focus-When-Using-Validation.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top