File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 1
- <UserControl x : Class =" MaterialDesignColors.WpfExample.Grids"
1
+ <UserControl x : Class =" MaterialDesignColors.WpfExample.Grids"
2
2
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
3
xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
4
4
xmlns : mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
46
46
Header =" Description"
47
47
MaxLength =" 255"
48
48
EditingElementStyle =" {StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
49
- <materialDesign : DataGridTextColumn Binding =" {Binding Numeric}"
49
+ <materialDesign : DataGridTextColumn Binding =" {Binding Numeric}"
50
50
Header =" Number with long header"
51
51
Width =" 120"
52
52
EditingElementStyle =" {StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" >
71
71
72
72
<!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
73
73
<materialDesign : DataGridComboBoxColumn Header =" Food" IsEditable =" True"
74
- SelectedValueBinding =" {Binding Food}"
75
- ItemsSourceBinding =" {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" >
74
+ SelectedValueBinding =" {Binding Food}"
75
+ ItemsSourceBinding =" {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" >
76
76
<!-- Setting the editing element style allows access to all of the combo box's properties
77
77
<materialDesign:MaterialDataGridComboBoxColumn.EditingElementStyle>
78
78
<Style TargetType="ComboBox" BasedOn="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type ComboBox}, ResourceId=MaterialDataGridComboBoxColumnEditingStyle}}" >
Original file line number Diff line number Diff line change @@ -144,9 +144,27 @@ private static void EnableCheckBoxAssistPropertyChangedCallback(DependencyObject
144
144
if ( dataGrid == null ) return ;
145
145
146
146
if ( ( bool ) dependencyPropertyChangedEventArgs . NewValue )
147
+ {
147
148
dataGrid . PreviewMouseLeftButtonDown += DataGridOnPreviewMouseLeftButtonDown ;
149
+ dataGrid . KeyDown += DataGridOnKeyDown ;
150
+ }
148
151
else
152
+ {
149
153
dataGrid . PreviewMouseLeftButtonDown -= DataGridOnPreviewMouseLeftButtonDown ;
154
+ dataGrid . KeyDown -= DataGridOnKeyDown ;
155
+ }
156
+ }
157
+
158
+ private static void DataGridOnKeyDown ( object sender , KeyEventArgs e )
159
+ {
160
+ if ( e . Key == Key . Space &&
161
+ e . OriginalSource is DataGridCell cell &&
162
+ cell . IsReadOnly == false &&
163
+ cell . Column is DataGridComboBoxColumn &&
164
+ sender is DataGrid dataGrid )
165
+ {
166
+ dataGrid . BeginEdit ( ) ;
167
+ }
150
168
}
151
169
152
170
private static void DataGridOnPreviewMouseLeftButtonDown ( object sender ,
@@ -159,7 +177,7 @@ private static void DataGridOnPreviewMouseLeftButtonDown(object sender,
159
177
160
178
while ( inputHitTest != null )
161
179
{
162
- var dataGridCell = inputHitTest as DataGridCell ;
180
+ var dataGridCell = inputHitTest as DataGridCell ;
163
181
if ( dataGridCell != null && dataGrid . Equals ( dataGridCell . GetVisualAncestry ( ) . OfType < DataGrid > ( ) . FirstOrDefault ( ) ) )
164
182
{
165
183
if ( dataGridCell . IsReadOnly ) return ;
You can’t perform that action at this time.
0 commit comments