2011-10-31 15 views
5

Böyle bir kullanıcı denetimi vardır:UserControls kullanırken wpf'de sekme sırası mı ayarlanıyor?

<UserControl x:Class="MySample.customtextbox" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" 
     d:DesignHeight="20" d:DesignWidth="300"> 
<Grid> 
    <TextBox x:Name="Ytextbox" Background="Yellow"/> 
</Grid> 

Ve bu bir pencerede kontrol ve set sekme siparişleri kullanmak ... ama benim pencere yüklendiğinde, sekme sırası düzgün çalışmıyor !!! penceremin kodu: Varsayılan olarak

<Window xmlns:my="clr-namespace:MySample" x:Class="MySample.window" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="window" Height="300" Width="600"> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
     <RowDefinition></RowDefinition> 

    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition></ColumnDefinition> 
     <ColumnDefinition></ColumnDefinition> 
     <ColumnDefinition></ColumnDefinition> 
     <ColumnDefinition></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <my:customtextbox Grid.Column="1" KeyboardNavigation.TabIndex="0" InfoText="{Binding msg}" Height="20"/> 
    <TextBox Grid.Column="3" KeyboardNavigation.TabIndex="1" Text="{Binding msg}" Height="20" Background="Gold"></TextBox> 
    <my:customtextbox Grid.Row="1" Grid.Column="1" KeyboardNavigation.TabIndex="2" InfoText="{Binding msg}" Height="20"/> 
    <TextBox Grid.Column="3" Grid.Row="1" Text="{Binding msg}" Height="20" KeyboardNavigation.TabIndex="3" Background="Gold"></TextBox> 

</Grid> 

cevap

7

, WPF aynı sekme düzeyinde, iç ve UserControl dışında, tüm denetimleri okur. UserControl içindeki kontrollerin bir TabIndex belirtilmemiş olduğundan, ilk sekme döngüsünden sonra bitecek sekmelere sahip olurlar.

genellikle kullanımı geçici üzerinde IsTabStop="False" ayarlamaktır benim UserControl (UserControl kendi üzerine sekme önlemek için) ve daha sonra UserControl içinde UserControl'ın TabIndex

<TextBox x:Name="Ytextbox" Background="Yellow" 
     TabIndex="{Binding Path=TabIndex, 
     RelativeSource={RelativeSource AncestorType={x:Type local:customtextbox}}}"/> 
iç Kontroller TabIndex bağlamak için bir TemplateBinding kullanımı

ve

<my:customtextbox IsTabStop="False" KeyboardNavigation.TabIndex="0" 
        Grid.Column="1" InfoText="{Binding msg}" Height="20"/> 
+0

Tank Rachel..its mükemmel çalışmasını –

+0

benim için iyi çalışıyor! – psulek

+0

Ya da özel usercontrol, yalnızca usercontrol ile geçerli kendi özel sekme sırasına sahip olan daha fazla denetime sahip olduğunda ' 'üzerindeki' KeyboardNavigation.TabNavigation = "Local" 'işlevini kullanabilirsiniz. – psulek