2014-03-07 68 views
0

我設計了一個wpf頁面。但我無法在網格視圖上設置「正確選項卡導航」。頁面上的控件(網格視圖)不遵循選項卡索引。頁面包含網格和保存,取消按鈕。焦點移動到網格視圖中第二行的第一個文本框

有一個gridview。這個網格有行和列。每行包含2個自動完成框和6個文本框。當我第一次輸入第一個自動完成框的值時,然後輸入它移動到下一個框的選項卡等等。我在上一個文本框中輸入數值,然後按回車鍵,然後網格中會形成一個新行。然後我按下焦點在外側按鈕(保存按鈕)上移動的標籤。 我想移動專注於下一個框(第一自動完成框,而不是保存按鈕),第二行中的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 > 

謝謝。 ..

+0

你能不能發佈XAML標記? – bit

回答

0

如果您希望TabNavigation在GridView中循環,並且不應離開GridView,請在GridView上設置KeyboardNavigation.TabNavigation="Cycle"

附加屬性KeyboardNavigation.TabNavigation可能枚舉模式可以找到here

參考:

enter image description here

+0

它不工作Rohit .... – Jinesh

+0

焦點不移動到第二個新行,移動到第一行tex盒.... – Jinesh

0

設置按鈕的IsTabStop=false

+0

謝謝,但焦點移動到第一行框...不是第二個.. – Jinesh

+0

你基本上必須刪除所有你不想專注於按TAB的控件的製表位。 – bit

+0

焦點不移動到第二個新行,移動到第一行tex ... – Jinesh

相關問題