我有一个与ItemsControl绑定的视图模型.在ItemsControl里面我有一个堆栈面板.现在我想要的是可以使用箭头键更改所选项目.就像在附图中我选择了第一项,当我按下第四项时应该选择.问题是每行的项目取决于屏幕分辨率,所以在某些屏幕上每行有4个项目,有些则有三个.其次,当我向下移动到页面结束时,滚动应该向下移动.我怎么能实现这个目标?
这是我的xaml:
<ScrollViewer HorizontalAlignment="Center" VerticalScrollBarVisibility="Auto" Width="Auto" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="2" VerticalAlignment="Top" Margin="0,10,0"> <ItemsControl Name="productvariants"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <DockPanel MouseLeftButtonDown="ProductvariantClicked" Tag="{Binding VariantCBX}" Margin="8" MaxHeight="160" MaxWidth="200" MinWidth="200" MinHeight="160"> <Border Name="ItemBorder" CornerRadius="6" BorderBrush="Gray" Background="White" BorderThickness="2" DockPanel.Dock="Top"> <StackPanel Margin="0"> <TextBlock Name="ProductvariantOption" Text="{Binding VariantOption}" HorizontalAlignment="Center" FontWeight="Bold" FontSize="20"/> <Image Source="{Binding ProductvariantlogoPath}" Height="80" Width="180" /> <TextBlock Text="{Binding vendorName}" HorizontalAlignment="Center" FontSize="15" FontWeight="Bold" /> <TextBlock Text="{Binding SellingPrice}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="Red" /> </StackPanel> </Border> </DockPanel> <DataTemplate.Triggers> <DataTrigger Binding="{Binding IsSelected}" Value="True" > <Setter TargetName="ItemBorder" Property="BorderBrush" Value="Yellow"/> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer>