2012-07-10 103 views
0

我有一个ListView,我试图禁用单个项目之间的键盘导航。 我试图将KeyboardNavigation.DirectionalNavigation =“None”设置为ListView,PanelTemplate以及单个项目。它没有工作。在ListView中禁用键盘箭头导航

此外,键盘方向导航是搞砸了 - 面板是一个wrappanel和按箭头导航混沌,有时它也循环之间两个孩子没有机会跳到其他箭头的机会。这就是为什么我想禁用,但纠正它会更好。

下面是相关代码:

<ListView IsTabStop="False" ItemsSource="{Binding Symbols}" SelectedItem="{Binding Selected,Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" KeyboardNavigation.DirectionalNavigation="None"> 

<ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel Orientation="Horizontal" Width="210" Margin="0,12" KeyboardNavigation.DirectionalNavigation="None" /> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 

<ListView.ItemTemplate> 
      <DataTemplate> 
       <Border Width="24" Height="24" Background="White" 
      BorderBrush="Black" BorderThickness="1 1 1 1" Margin="0" 
         KeyboardNavigation.IsTabStop="False" KeyboardNavigation.DirectionalNavigation="None"> 
        <TextBlock Text="{Binding Text}" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="textBlock" FontFamily="Verdana, Arial"/> 
       </Border> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
+0

使用KeyboardNavigation.DirectionalNavigation = “无” 到一个ListBoxItem – JSJ 2012-07-10 11:45:05

回答

1

只需添加一个处理PreviewKeyDown事件:

private void listView1_PreviewKeyDown(object sender, KeyEventArgs e) 
    { 
     switch(e.Key) 
     { 
      case Key.Left: 
      case Key.Right: 
      case Key.Up: 
      case Key.Down: 
       e.Handled = true; 
       break; 
      default: 
       break; 
     } 
    }