2

I'm trying to figure out how to get the spacebar to toggle the checkbox (located in the first column of each row) when any part of that row is selected.

Here's the setup:

      <ui:DataGridEx ItemsSource="{Binding ListOfThings}"
                 SortingCallback="{Binding Sorting}"
                 SelectionChangedCallback="{Binding SelectionChanged}"
                 SelectionMode="Extended"
                 GridLinesVisibility="None"
                 AutoGenerateColumns="False"
                 HeadersVisibility="Column"
                 ScrollViewer.CanContentScroll="True">
     <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
           <Setter Property="BorderThickness" Value="0"/>
           <Setter Property="ToolTip" Value="{StaticResource UnhelpfulTooltip}"/>
           <Setter Property="ToolTipService.ShowDuration" Value="20000"/>
           <Setter Property="IsTabStop" Value="False"/>
        </Style>
     </DataGrid.CellStyle>
     <DataGrid.Columns>
        <DataGridTemplateColumn CanUserSort="False" >
           <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                 <CheckBox IsChecked="{Binding Path=Enabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                           HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,2.5,5,2.5" IsEnabled="True" />
              </DataTemplate>
           </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTemplateColumn CanUserSort="False" >
           <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                 <Image Style="{StaticResource ImageOfSomeAwesome}" VerticalAlignment="Center" Margin="5,2.5,5,2.5" /> 
              </DataTemplate>
           </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Green!"
                            CanUserSort="True"
                            Foreground="DarkGreen"/>
        <DataGridTextColumn Header="Magenta!"
                            CanUserSort="True"
                            Foreground="DarkMagenta"/>
        <DataGridTextColumn Header="Blue!"
                            CanUserSort="True"
                            Foreground="MidnightBlue"/>
        <DataGridTextColumn Header="Goldenrod!"
                            CanUserSort="True"
                            Foreground="DarkGoldenrod"/>
        <DataGridTextColumn Header="Cyan!"
                            CanUserSort="True"
                            Foreground="DarkCyan"/>
        <DataGridTextColumn Header="Yellow AND green!"
                            CanUserSort="True"
                            Foreground="YellowGreen"/>
     </DataGrid.Columns>
  </ui:DataGridEx>

If I select a row using the mouse, hitting the spacebar does nothing. If I check or uncheck the checkbox using the mouse, the hitting the space bar does check / uncheck the checkbox. If I tab to the next row, the spacebar also works, but the checkbox itself has the ugly dotted line around the edge to show that it's selected (which doesn't happen if I check it with the mouse). enter image description here vs enter image description here

Is there a way to get the spacebar to check / uncheck the box if I after selecting the row by only changing the xaml? Or do I need to manually handle the OnKeyDown event in the VM?

Ash
  • 379
  • 1
  • 3
  • 14

0 Answers0