There is a markup:
<ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="400" Style="{DynamicResource ScrollViewerDefaultStyle}"> <ItemsControl x:Name="_allTags" ItemsSource="{Binding}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Width="{Binding Path=ActualWidth, ElementName=SearchTextBox}" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate DataType="{x:Type s:String}"> <Button Template="{StaticResource ItemTemplate}" PreviewKeyDown="PreviewHashTag_KeyDown" Click="Item_Click"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> There is a code that, when you press Down in the text field (the code does not bring it) transfers the focus to the ItemsControl, where you can then freely move between items using the arrows. But it was so until I registered the style: ScrollViewerDefaultStyle
Style:
<Style x:Key="ScrollViewerDefaultStyle" TargetType="{x:Type ScrollViewer}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ScrollContentPresenter KeyboardNavigation.DirectionalNavigation="Cycle" Grid.ColumnSpan="2" Grid.RowSpan="2" CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}"/> <ScrollBar x:Name="PART_VerticalScrollBar" Style="{StaticResource ScrollBarStyle}" Orientation="Vertical" Grid.Column="1" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/> <ScrollBar x:Name="PART_HorizontalScrollBar" Style="{StaticResource ScrollBarStyle}" Orientation="Horizontal" Grid.Row="1" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> After I applied the style, when I press Down, the focus is transferred, but the navigation is not on items, but on the whole ScrollViewer, i.e. there is a simple scrolling. I can not understand what is responsible for this.
It was played with KeyboardNavigation.DirectionalNavigation, but it led nowhere. Help me to understand.
KeyboardNavigation.DirectionalNavigation- Andrey NOP