焦点移动到网格视图中第二行的第一个文本框

时间:2014-03-07 08:53:21

标签: c# wpf gridview tabs

我设计了一个wpf页面。但我无法在网格视图上设置正确的选项卡导航。页面上的控件(网格视图)不遵循选项卡索引。页面包含网格和保存,取消按钮。

有一个gridview。该网格具有行和列。每行包含2个自动完成框和6个文本框。首先我在第一个自动完成框中输入值,然后输入tab它移动到下一个框,依此类推。我在最后一个文本框中输入值并按下回车键,然后在网格中形成一个新行。然后我按下它对焦的标签移动到外部按钮(保存按钮)。       我想将焦点移到grid.Pls帮助中的下一个框(第一个自动完成框,而不是保存按钮)上。

XAML

  <GridView KeyboardNavigation.IsTabStop="False" >
                                <GridViewColumn Header="Id" Width="0" DisplayMemberBinding="{Binding Path=PurchaseItemId}"></GridViewColumn>
                                <GridViewColumn Header="No." Width="20" DisplayMemberBinding="{Binding Path=No, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"></GridViewColumn>
                                <GridViewColumn Header="ItemId" Width="0" DisplayMemberBinding="{Binding Path=ItemId}"></GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Item Code" Width="60">

                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <StackPanel>
                                                <!--<TextBox  x:Name="txtItemCode" Width="60"  Text="{Binding Path=ItemCode, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" TabIndex="2" />-->
                                                <my:AutoCompleteBox Canvas.Left="295" Canvas.Top="393" Name="txtItemCode" Text="{Binding Path=ItemCode, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ItemsSource="{Binding Path=AutoCompleteBoxCodes, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                                                                    SelectedItem="{Binding Path=AutoCompleteBoxSelectedCode1, NotifyOnValidationError=True, ValidatesOnDataErrors=True,UpdateSourceTrigger=LostFocus, Mode=TwoWay}" IsTextCompletionEnabled="True" TextChanged="txtItemCode_TextChanged" KeyDown="txtItemCode_KeyDown" SelectionChanged="txtItemCode_SelectionChanged" />

                                                <!--<ListBox x:Name="lstItemCodes" Width="250" Height="100" ItemsSource="{Binding Path=PurchaseItemCodes}" Visibility="{Binding Path=IsItemCodeListVisible}" SelectedItem="{Binding Path=SelectedItemCode1, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel Orientation="Horizontal">
                                                                <TextBlock Text="{Binding Path=Code}" />
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>-->
                                            </StackPanel>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Item Name" Width="120">
                                    <GridViewColumn.CellTemplate >

                                        <DataTemplate>
                                            <StackPanel>
                                                <my:AutoCompleteBox   Canvas.Left="295" Canvas.Top="393" Name="txtItemName" Text="{Binding Path=ItemName, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ItemsSource="{Binding Path=AutoCompleteBoxNames, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                                                                    SelectedItem="{Binding Path=AutoCompleteBoxSelectedName1, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" IsTextCompletionEnabled="True" Width="100" TextChanged="txtItemName_TextChanged" PreviewKeyDown="txtItemName_PreviewKeyDown" IsHitTestVisible="True" />
                                                <!--<TextBox Name="txtItemName" Width="120"  Text="{Binding Path=ItemName, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>
                                                <ListBox x:Name="lstItemNames" Width="250" Height="70" ItemsSource="{Binding Path=PurchaseItems}" Visibility="{Binding Path=IsItemListVisible}" SelectedItem="{Binding Path=SelectedItem1, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Bottom" AllowDrop="False">
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel Orientation="Vertical">
                                                                <TextBlock Text="{Binding Path=Name}" FontWeight="ExtraBlack" />
                                                                <TextBlock Text="{Binding Path=Category.CategoryName}" />

                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>-->
                                            </StackPanel>
                                        </DataTemplate>

                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Qty" Width="50" >
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox x:Name="txtQuantity" Width="45"  Text="{Binding Path=Quantity, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" TextChanged="txtQuantity_TextChanged" PreviewTextInput="txtQuantity_PreviewTextInput" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Purchase Price" Width="80">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox x:Name="txtPurchasePrice" Width="60"  Text="{Binding Path=Purchaseprice, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="txtPurchasePrice_PreviewTextInput" TextChanged="txtPurchasePrice_TextChanged" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Unit" Width="70">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <ComboBox Canvas.Left="10" Canvas.Top="10" Height="23" Name="cmbUnit" Width="55" ItemsSource="{StaticResource UnitData }" SelectedItem="{Binding Path=Unit}">


                                            </ComboBox>

                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="ProfitAmount" Width="75">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtProfitAmount" Width="70"  Text="{Binding Path=ProfitAmount, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" TextChanged="txtProfitAmount_TextChanged" PreviewTextInput="txtProfitAmount_PreviewTextInput" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Profit %" DisplayMemberBinding="{Binding Path=ProfitPercent, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Width="50">
                                    <!--<GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtProfitPercent" Width="80"  Text="{Binding Path=ProfitPercent, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="False"  />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>-->
                                </GridViewColumn>

                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Selling Price" DisplayMemberBinding="{Binding Path=SellingPrice, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Width="70">
                                    <!--<GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtSellingPrice" Width="100"  Text="{Binding Path=SellingPrice, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="False"  />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>-->
                                </GridViewColumn>

                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Tax" Width="40">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtTax" Width="35"  Text="{Binding Path=Tax, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" TextChanged="txtTax_TextChanged" PreviewTextInput="txtTax_PreviewTextInput" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="Description" Width="80">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtDescription" Width="75"  Text="{Binding Path=Description, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn  HeaderContainerStyle="{StaticResource hcs}" Header="ShelfLocation" Width="100">
                                    <GridViewColumn.CellTemplate >
                                        <DataTemplate>
                                            <TextBox Name="txtShelfLocation" Width="120"  Text="{Binding Path=ShelfLocation, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" KeyDown="txtShelfLocation_KeyDown" />
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                 <GridViewColumn Header="Total" Width="80" DisplayMemberBinding="{Binding Path=Total, UpdateSourceTrigger=PropertyChanged}"></GridViewColumn>
                            </GridView >

谢谢...

2 个答案:

答案 0 :(得分:0)

为按钮设置IsTabStop=false

答案 1 :(得分:0)

如果您希望TabNavigation在GridView中循环并且不应离开GridView,请在GridView上设置KeyboardNavigation.TabNavigation="Cycle"

可以找到KeyboardNavigation.TabNavigation附加属性的可能枚举模式here

供参考:

enter image description here