Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's interesting that setting the KeyboardNavigation directly on the DataGridTextColumn's doesn't work. An alternative that should work is to set up a DataGridCell style.</p> <pre><code>&lt;toolkit:DataGrid.CellStyle&gt; &lt;Style TargetType="{x:Type toolkit:DataGridCell}"&gt; &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="False" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="True" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/toolkit:DataGrid.CellStyle&gt; </code></pre> <p>Attaching this to the DataGrid will ensure that a cell is only a TabStop if it is already selected. However, if you are selecting full rows and don't have SelectionUnit="Cell" set on the DataGrid, it will still cycle through each column of the currently selected row.</p> <p>Instead, we can create multiple CellStyles as resources within the DataGrid:</p> <pre><code>&lt;toolkit:DataGrid.Resources&gt; &lt;Style x:Key="SelectableCellStyle" TargetType="{x:Type toolkit:DataGridCell}"&gt; &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="False" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="True" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type toolkit:DataGridCell}"&gt; &lt;Setter Property="KeyboardNavigation.IsTabStop" Value="False" /&gt; &lt;/Style&gt; &lt;/toolkit:DataGrid.Resources&gt; </code></pre> <p>Now we have a style being applied to all DataGridCells by default and turning off TabStop, and a keyed style that allows selection when the Cell (or whole Row) is selected. Applying this style to only a single column will give us the same single-tab-in effect while allowing the whole row and all of it's columns to be selected.</p> <pre><code> &lt;my:DataGridTextColumn x:Name="ID" Header="ID" Width="1*" CellStyle={StaticResource SelectableCellStyle}"/&gt; </code></pre> <p>This does also stop tabbing into the DataGrid if nothing is selected, which may be preferred or not depending on the situation you are using it in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload