2012-08-29 3 views
0

항목을 가로로 표시하는 ListView가 있습니다. 각 Item은 1 열 그리드입니다. 외관은 열의 수가 동적 인 격자 모양입니다. 이 모든 것은 작동하고 탭 탐색을 제외하고 내가 원했던 것처럼 보입니다. 나는 KeyboardNavigation.TabNavigation="Continue"을 ListView에 설정하고 항목의 각 행을 통해 다음 항목 등으로 나를 허용하고있는 ItemContainerStyle에서 KeyboardNavigation.IsTabStop을 false로 설정했습니다. 그러나 처음부터 탭을 사용하고 싶습니다. 첫 번째 항목의 행을 두 번째 항목의 첫 번째 행에 연결 한 다음 등을 다음 행으로 가져옵니다.ListView 탭 탐색 ListViewItems가 Grid 일 때의 열 탐색

Ex.

Item1Row1 -> Item2Row1 -> Item3Row1 -> ...

Item1Row2 -> Item2Row2 -> Item3Row2 -> ...

나는 컨트롤에 대한 설정 탭 인덱스가 각 셀 (내가 옳은지 테스트했다),하지만 ListView/ListViewItems 내에서 TabIndexes를 활성화하는 데 필요한 설정을 파악할 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다. 여기에 xaml이 있습니다 ...

<ListView VerticalAlignment="Top" Background="Transparent" BorderThickness="0" KeyboardNavigation.TabNavigation="Continue" ItemsSource="{Binding RawProductDataItemViewModels}"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.ItemContainerStyle> 
     <Style TargetType="{x:Type ListViewItem}"> 
      <Setter Property="Focusable" Value="False"/> 
      <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/> 
     </Style> 
    </ListView.ItemContainerStyle> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <Grid VerticalAlignment="Top" Margin="2.5,0,2.5,0"> 
       <Grid.RowDefinitions> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
        <RowDefinition SharedSizeGroup="ButtonAndGridGroup"/> 
       </Grid.RowDefinitions> 

       <TextBlock Margin="5,4,0,0" Grid.Row="0"> 
         <TextBlock.Text> 
          <MultiBinding StringFormat="Lane #{0}"> 
           <Binding Path="Lane"/> 
          </MultiBinding> 
         </TextBlock.Text> 
       </TextBlock> 
       <TextBox Grid.Row="1" Margin="0,4,0,0" Width="75" Text="{Binding RollNumber, StringFormat='{}{0:#####-#}', TargetNullValue=''}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=1}"/> 
       <TextBox Grid.Row="2" Margin="0,4,0,0" Width="75" Text="{Binding PCode}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=2}"/> 
       <TextBox Grid.Row="3" Margin="0,4,0,0" Width="75" Text="{Binding RollWidth}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=3}"/> 
       <TextBox Grid.Row="4" Margin="0,4,0,0" Width="75" Text="{Binding RollWeight}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=4}"/> 
       <TextBox Grid.Row="5" Margin="0,4,0,0" Width="75" Text="{Binding GrossWeight}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=5}"/> 
       <TextBox Grid.Row="6" Margin="0,4,0,0" Width="75" Text="{Binding BurnWeight}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=6}"/> 
       <TextBox Grid.Row="7" Margin="0,4,0,0" Width="75" Text="{Binding SqFtWeight}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=7}"/> 
       <TextBox Grid.Row="8" Margin="0,4,0,0" Width="75" Text="{Binding Cure}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=8}"/> 
       <TextBox Grid.Row="9" Margin="0,4,0,0" Width="75" Text="{Binding Rigidity}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=9}"/> 
       <TextBox Grid.Row="10" Margin="0,4,0,0" Width="75" Text="{Binding Telescope}" 
          TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=10}"/> 
      </Grid> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

답변

0

나는 이것을 코드에서 처리하기로 결정했습니다. xaml의 텍스트 상자에서 탭 인덱스를 제거했습니다. 그 해결책은별로 좋지는 않지만, 필자가 생각하기에 목록 상자를 제거하고 모든 차선을 harcoding하여 탭 인덱스를 사용할 수있게하는 것이 더 좋습니다. ListView에에

미리보기 키 아래 처리기 :

private void LanesListView_PreviewKeyDown(object sender, KeyEventArgs e) 
{ 
    UIElement uie = e.OriginalSource as UIElement; 

    // 'Ctrl + Tab' or 'Shift + Enter' (Reverse Tab) 
    if ((e.Key == Key.Tab || e.Key == Key.Return) && 
     (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift && 
     uie != null) 
    { 
     MoveFocusPrevious(uie, (UIElement)sender); 

     e.Handled = true; 
    } 
    else if ((e.Key == Key.Tab || e.Key == Key.Return) && uie != null) 
    { 
     // Normal 'Enter' or 'Tab' key click 
     MoveFocusNext(uie, (UIElement)sender); 

     e.Handled = true; 
    } 
} 

이동 초점 방법 :

private void MoveFocusNext(UIElement uie, UIElement sender) 
{ 
    if(!uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right))) 
    { 
     uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); // Move Down 
     uie = (UIElement)Keyboard.FocusedElement; 
     MoveFocusToFirst(uie, sender); // Move to to first 
    } 
} 

private void MoveFocusPrevious(UIElement uie, UIElement sender) 
{ 
    if (!uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left))) 
    { 
     uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous)); // Move Up 
     uie = (UIElement)Keyboard.FocusedElement; 
     MoveFocusToLast(uie, sender); // Move focus to last 
    } 
} 

private void MoveFocusToLast(UIElement uie, UIElement sender) 
{ 
    bool isLast = false; 

    // Move right until hitting last item 
    while(!isLast) 
    { 
     // If Focus cannot be moved, it is last item. 
     isLast = !uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right)); 
     uie = (UIElement)Keyboard.FocusedElement; 
    } 
} 

private void MoveFocusToFirst(UIElement uie, UIElement sender) 
{ 
    bool isFirst = false; 

    // Move left until hitting last item 
    while (!isFirst) 
    { 
     // If Focus cannot be moved, it is last item. 
     isFirst = !uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left)); 
     uie = (UIElement)Keyboard.FocusedElement; 
    } 
}