Domanda

Sto usando IDataErrorInfo per convalidare e indicare gli errori nelle mie caselle di testo. Mi sto trovando devo scheda una volta per la casella di testo e una volta per l'adornerdecorator.

Ho un modello di errore:

<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 modello di testo:

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

e dichiarare una casella di testo come questo:

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

Se l'adorner è rotondo casella di un testo come sopra allora io scheda una volta di lasciare la casella di testo e una volta a lasciare il 'ornamento' (sembra) Se ho l'adorner intorno ad uno StackPanel di caselle di testo poi ho scheda una volta ogni per le caselle di testo poi devono tornare indietro attraverso tutti i 'ornamenti', a sua volta. Quando tabulazione attraverso gli ornamenti l'attenzione va sul bordo rosso definito nel modello di controllo ..

tutte le idee?

grazie

È stato utile?

Soluzione

Aggiungi questo alla sezione risorse della finestra:

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

Per ulteriori informazioni consultare il mio blog: http://www.nbdtech.com/blog/archive/2008/05/25/WPF-Problems-with-Keyboard-Focus-When-Using-Validation.aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top