ListView的标签导航横跨在那里ListViewItems是网格列 [英] ListView Tab Navigation Across Columns where ListViewItems are Grids

查看:115
本文介绍了ListView的标签导航横跨在那里ListViewItems是网格列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有水平presents项目一个ListView。每个项目都是一个1列网格。外观是一个方格,列数是动态的。所有这些工作,看起来像我希望它,除了标签导航。我有 KeyboardNavigation.TabNavigation =继续设置的ListView和有KeyboardNavigation.IsTabStop设置为false在ItemContainerStyle,这让我通过一个项目的每一行,然后到下一个项目,等等。然而,我想从第一行选项卡中的第一项的第一行中的第二项,等等,那么到下一行。

防爆。


  

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


  
  

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


我已经建立了在每个单元的控制选项卡索引(我已经测试是正确的),但我想不出我需要启用一个ListView / ListViewItems内TabIndexes什么设置。任何帮助将大大AP preciated。这里的XAML ...

 < ListView的VerticalAlignment =评出的背景=透明了borderThickness =0KeyboardNavigation.TabNavigation =继续的ItemsSource ={结合RawProductDataItemViewModels}>
    < ListView.ItemsPanel>
        < ItemsPanelTemplate>
            < StackPanel的方向=横向/>
        < / ItemsPanelTemplate>
    < /ListView.ItemsPanel>
    < ListView.ItemContainerStyle>
        <风格的TargetType ={X:类型的ListViewItem}>
            < setter属性=调焦VALUE =FALSE/>
            < setter属性=KeyboardNavigation.IsTabStopVALUE =FALSE/>
        < /样式和GT;
    < /ListView.ItemContainerStyle>
    < ListView.ItemTemplate>
        <&DataTemplate的GT;
            <电网VerticalAlignment =评出的保证金=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的保证金=5,4,0,0Grid.Row =0>
                        < TextBlock.Text>
                            < MultiBinding的StringFormat =#巷{0}>
                                <绑定路径=里/>
                            < / MultiBinding>
                        < /TextBlock.Text>
                < / TextBlock的>
                <文本框Grid.Row =1保证金=0,4,0,0WIDTH =75文本={结合RollNumber,的StringFormat ='{} {0:##### - #}' ,TargetNullValue =''}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 1}/>
                <文本框Grid.Row =2保证金=0,4,0,0WIDTH =75文本={结合P code}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 2}/>
                <文本框Grid.Row =3保证金=0,4,0,0WIDTH =75文本={结合RollWidth}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 3}/>
                <文本框Grid.Row =4保证金=0,4,0,0WIDTH =75文本={结合RollWeight}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 4}/>
                <文本框Grid.Row =5保证金=0,4,0,0WIDTH =75文本={结合毛重}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 5}/>
                <文本框Grid.Row =6保证金=0,4,0,0WIDTH =75文本={结合BurnWeight}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 6}/>
                <文本框Grid.Row =7保证金=0,4,0,0WIDTH =75文本={结合SqFtWeight}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 7}/>
                <文本框Grid.Row =8保证金=0,4,0,0WIDTH =75文本={结合治疗}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 8}/>
                <文本框Grid.Row =9保证金=0,4,0,0WIDTH =75文本={结合刚性}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 9}/>
                <文本框Grid.Row =10保证金=0,4,0,0WIDTH =75文本={结合望远镜}
                            的TabIndex ={结合巷,转换器= {StaticResource的IntegersTo2DIndex},ConverterParameter = 10}/>
            < /网格和GT;
        < / DataTemplate中>
    < /ListView.ItemTemplate>
< /&的ListView GT;


解决方案

我决定在code来处理这个落后。我取消了在XAML文本框的标签索引。该解决方案是不是pretty,但最好是,在我看来,不是删除列表框和harcoding所有的车道,这样我可以使用标签索引。

preVIEW键按下处理程序上的ListView:

 私人无效LanesListView_ previewKeyDown(对象发件人,发送KeyEventArgs E)
{
    UIE的UIElement = e.OriginalSource为的UIElement;    //'Ctrl + Tab键或Shift +回车(Reverse选项卡)
    如果((e.Key == Key.Tab || e.Key == Key.Return)及&放大器;
        (Keyboard.Modifiers&安培; ModifierKeys.Shift)== ModifierKeys.Shift和放大器;&安培;
         UIE!= NULL)
    {
        MoveFocus previous(UIE,(的UIElement)发送者);        e.Handled =真实的;
    }
    否则如果((e.Key == Key.Tab || e.Key == Key.Return)及&放大器;!UIE =空)
    {
        //正常Enter键或Tab键点击
        MoveFocusNext(UIE,(的UIElement)发送者);        e.Handled =真实的;
    }
}

移动对焦方式:

 私人无效MoveFocusNext(UIE的UIElement,发送者的UIElement)
{
    如果(!uie.MoveFocus(新TraversalRequest(FocusNavigationDirection.Right)))
    {
        uie.MoveFocus(新TraversalRequest(FocusNavigationDirection.Next)); //下移
        UIE =(的UIElement)Keyboard.FocusedElement;
        MoveFocusToFirst(UIE,发送者); //先移动向
    }
}私人无效MoveFocus previous(UIE的UIElement,发送者的UIElement)
{
    如果(!uie.MoveFocus(新TraversalRequest(FocusNavigationDirection.Left)))
    {
        uie.MoveFocus(新TraversalRequest(FocusNavigationDirection previous)); // 提升
        UIE =(的UIElement)Keyboard.FocusedElement;
        MoveFocusToLast(UIE,发送者); //将焦点移动到最后
    }
}私人无效MoveFocusToLast(UIE的UIElement,发送者的UIElement)
{
    布尔isLast = FALSE;    //向右移动,直到打最后一个项目
    而(!isLast)
    {
        //如果焦点不能移动,这是最后一个项目。
        isLast = uie.MoveFocus(新TraversalRequest(FocusNavigationDirection.Right))!;
        UIE =(的UIElement)Keyboard.FocusedElement;
    }
}私人无效MoveFocusToFirst(UIE的UIElement,发送者的UIElement)
{
    布尔isFirst = FALSE;    //向左移动,直到打最后一个项目
    而(!isFirst)
    {
        //如果焦点不能移动,这是最后一个项目。
        !isFirst = uie.MoveFocus(新TraversalRequest(FocusNavigationDirection.Left));
        UIE =(的UIElement)Keyboard.FocusedElement;
    }
}

I have a ListView that presents items horizontally. Each Item is a 1 column Grid. The appearance is of a grid where the number of columns is dynamic. All of this works and looks like I want it to, except tab navigation. I have KeyboardNavigation.TabNavigation="Continue" set on the ListView and have KeyboardNavigation.IsTabStop set to false on the ItemContainerStyle, which is allowing me to through each row in a item, then on to the next item, etc. However, I would like to tab from the first row in the first item to the first row in the second item, etc. then on to the next row.

Ex.

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

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

I have tab indexes set up for the controls in each cell (which I have tested are correct), but I can't figure out what settings I need to enable TabIndexes within a ListView/ListViewItems. Any help would be greatly appreciated. Here's the 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>

解决方案

I decided to handle this in the code behind. I removed the tab indexes on the textboxes in xaml. The solution isn't pretty, but it is better, in my opinion, than removing the listbox and harcoding all the lanes so that I can use tab indexes.

Preview Key Down Handler on 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;
    }
}

Move Focus Methods:

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; 
    }
}

这篇关于ListView的标签导航横跨在那里ListViewItems是网格列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆