嵌入式用户控件中的TabStop在不必要的控件处停止

时间:2018-08-24 06:37:09

标签: wpf wpf-controls

我正在尝试在窗口中设置适当的制表位。它停止在我要传递的其他元素上。我曾尝试在多个地方使用KeyboardNavigation.IsTabStop = "False"IsTabStop="False",但没有帮助。任何人都可以帮我解决问题吗?

窗口:

<Grid Grid.Row="3" Background="White" Margin="12,5,15,7">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Label Content="File Name:" />
    <Label Grid.Row="1" Content="Tags:" IsTabStop="False"/>

    <TextBox Grid.Column="1" x:Name="FileNameTextBox" />

    <autocompletebox:AutocompleteTextbox Grid.Row="1" Grid.Column="1" Focusable="True" IsTabStop="False"/>

    <StackPanel Grid.Row="2" Grid.ColumnSpan="2">
           <Button Content="Cancel" Command="{Binding CancelCommand}" />
           <Button Content="Save" Command="{Binding SaveChangesCommand}" />
    </StackPanel>
</Grid>

当我跳出FileNameTextBox控件时,AutocompleteTextBox将获得键盘焦点。我的AutocompleteTextBox如下:

<Grid Background="White" IsHitTestVisible="True">
        <Grid.InputBindings>
            <MouseBinding Gesture="LeftClick" Command="{Binding SetFocusCommand}" />
        </Grid.InputBindings>
        <WrapPanel Orientation="Horizontal" x:Name="WrapPanelTags">
            <ListView x:Name="TagsListView" ItemContainerStyle="{StaticResource ContainerStyle}" Padding="6" Style="{StaticResource MyListView}"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" Focusable="False">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ListView>
        </WrapPanel>
        <Popup x:Name="SuggestionsPopup" AllowsTransparency="True" Placement="Bottom" IsOpen="{Binding IsSuggestionListOpen}" >
            <ListBox x:Name="SuggestionList" ItemsSource="{Binding HashTagSuggestionList}" Focusable="True" KeyboardNavigation.DirectionalNavigation="Cycle"
                      ItemContainerStyle="{StaticResource SuggestionsContainerStyle}" MinWidth="100"
                      SelectedItem="{Binding SelectedSuggestion, UpdateSourceTrigger=PropertyChanged}" IsHitTestVisible="True">
            </ListBox>
        </Popup>
    </Grid>

当AutocompleteTextBox获得键盘焦点时,聚焦的元素是ListViewItem,我可以从here的以下逻辑中找到它:

IInputElement focusedControl =  Keyboard.FocusedElement;

我的listviewitems包含2种控件-自定义控件和一个文本框。当我的AutocompleteTextbox获得键盘焦点时,我只希望文本框获得焦点,而不希望其他自定义控件。我已将KeyboardNavigation.IsTabStop="False"添加到自定义控件的数据模板中。

<DataTemplate DataType="{x:Type hashTag:Hashtag}">
     <Border x:Name="TagDataTemplate" CornerRadius="2" BorderThickness="1" KeyboardNavigation.IsTabStop="False">
           <Grid KeyboardNavigation.IsTabStop="False">....</Grid>
     </Border>
 </DataTemplate>

请让我知道是否需要进一步的信息。

0 个答案:

没有答案