Skip to content

Commit 065b4ad

Browse files
authored
DataGrid selection should now properly select item (#2378)
This should now both have the click to edit and the selection. Fixes #2363
1 parent 1795360 commit 065b4ad

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

MaterialDesignThemes.Wpf/DataGridAssist.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using System.Windows;
34
using System.Windows.Controls;
@@ -217,7 +218,7 @@ private static void AllowDirectEditWithoutFocus(object sender, MouseButtonEventA
217218
if (dataGridCell?.Content is UIElement element)
218219
{
219220
var dataGrid = (DataGrid)sender;
220-
221+
221222
// Check if the cursor actually hit the element and not just the cell
222223
var mousePosition = mouseArgs.GetPosition(element);
223224
var elementHitBox = new Rect(element.RenderSize);
@@ -232,6 +233,14 @@ private static void AllowDirectEditWithoutFocus(object sender, MouseButtonEventA
232233

233234
dataGrid.CurrentCell = new DataGridCellInfo(dataGridCell);
234235
dataGrid.BeginEdit();
236+
//Begin edit likely changes the visual tree, trigger the mouse down event to cause the DataGrid to adjust selection
237+
var mouseDownEvent = new MouseButtonEventArgs(mouseArgs.MouseDevice, mouseArgs.Timestamp, mouseArgs.ChangedButton)
238+
{
239+
RoutedEvent = Mouse.MouseDownEvent,
240+
Source = mouseArgs.Source
241+
};
242+
243+
dataGridCell.RaiseEvent(mouseDownEvent);
235244

236245
switch (dataGridCell?.Content)
237246
{

0 commit comments

Comments
 (0)