2011-10-31 2 views
5

私はこのようなユーザーコントロールがあります。UserControlsから使用する場合、wpfのタブ順序を設定しますか?

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

をそして私は、このウィンドウ内のコントロールと設定のタブオーダーを使用して...しかし、私の窓がロードされたとき、タブ順序が正しく動作していません!!! 私の窓コード:デフォルトで

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

答えて

7

を、WPFは、同じタブレベルで、ユーザーコントロールの内側と外側で、すべてのコントロールを読み込みます。 UserControl内のコントロールにはTabIndexが指定されていないため、最初のタブサイクルの後にタブ付きになります。

私は通常使用の回避策は、私のUserControlIsTabStop="False"を設定することです(ユーザーコントロール自体にタブ移動を防ぐため)、その後、UserControl内UserControlのTabIndex

<TextBox x:Name="Ytextbox" Background="Yellow" 
     TabIndex="{Binding Path=TabIndex, 
     RelativeSource={RelativeSource AncestorType={x:Type local:customtextbox}}}"/> 
に内部統制 TabIndexにバインドする TemplateBindingを使用

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

戦車あなたRachel..itsは完璧に動作 –

+0

は私のためによく働きます! – psulek

+0

また、独自のusercontrolに、usercontrolでのみ有効な独自の特定のタブ順序を持つより多くのコントロールがある場合に、 ''で 'KeyboardNavigation.TabNavigation =" Local " – psulek