Skip to content

Commit 3755b7d

Browse files
authored
Merge pull request #3374 from windows-toolkit/user/regisb/DataGridWinUIFixes
DataGrid fixes for WinUI 3 usage
2 parents 5276cd2 + a99c1ea commit 3755b7d

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGrid.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5653,7 +5653,7 @@ private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
56535653
ShowScrollBars();
56545654

56555655
// If the DataGrid itself got focus, we actually want the automation focus to be on the current element
5656-
if (e.OriginalSource == this && AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged))
5656+
if (e.OriginalSource as Control == this && AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged))
56575657
{
56585658
DataGridAutomationPeer peer = DataGridAutomationPeer.FromElement(this) as DataGridAutomationPeer;
56595659
if (peer != null)
@@ -5684,7 +5684,7 @@ private void DataGrid_KeyDown(object sender, KeyRoutedEventArgs e)
56845684

56855685
private void DataGrid_KeyUp(object sender, KeyRoutedEventArgs e)
56865686
{
5687-
if (e.Key == VirtualKey.Tab && e.OriginalSource == this)
5687+
if (e.Key == VirtualKey.Tab && e.OriginalSource as Control == this)
56885688
{
56895689
if (this.CurrentColumnIndex == -1)
56905690
{
@@ -6239,7 +6239,7 @@ private void FlushCurrentCellChanged()
62396239

62406240
// If the DataGrid itself has focus, we want to move automation focus to the new current element
62416241
object focusedObject = FocusManager.GetFocusedElement();
6242-
if (focusedObject == this && AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged))
6242+
if (focusedObject as Control == this && AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged))
62436243
{
62446244
peer.RaiseAutomationFocusChangedEvent(this.CurrentSlot, this.CurrentColumnIndex);
62456245
}
@@ -6716,7 +6716,7 @@ private void PreparingCellForEditPrivate(FrameworkElement editingElement)
67166716
{
67176717
if (_editingColumnIndex == -1 ||
67186718
this.CurrentColumnIndex == -1 ||
6719-
this.EditingRow.Cells[this.CurrentColumnIndex].Content != editingElement)
6719+
this.EditingRow.Cells[this.CurrentColumnIndex].Content as FrameworkElement != editingElement)
67206720
{
67216721
// The current cell has changed since the call to BeginCellEdit, so the fact
67226722
// that this element has loaded is no longer relevant

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridCell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ private void DataGridCell_PointerTapped(object sender, TappedRoutedEventArgs e)
450450
if (this.OwningRow != null)
451451
{
452452
Debug.Assert(sender is DataGridCell, "Expected sender is DataGridCell.");
453-
Debug.Assert(sender == this, "Expected sender is this.");
453+
Debug.Assert(sender as ContentControl == this, "Expected sender is this.");
454454
e.Handled = this.OwningGrid.UpdateStateOnTapped(e, this.ColumnIndex, this.OwningRow.Slot, !e.Handled /*allowEdit*/);
455455
this.OwningGrid.UpdatedStateOnTapped = true;
456456
}

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridColumnHeader.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,7 @@ private void SetOriginalCursor()
10651065
{
10661066
Debug.Assert(interactionInfo.OriginalCursor != null, "Expected non-null interactionInfo.OriginalCursor.");
10671067

1068-
if (Window.Current != null)
1069-
{
1070-
Window.Current.CoreWindow.PointerCursor = interactionInfo.OriginalCursor;
1071-
}
1068+
CoreWindow.GetForCurrentThread().PointerCursor = interactionInfo.OriginalCursor;
10721069

10731070
interactionInfo.ResizePointerId = 0;
10741071
}
@@ -1103,14 +1100,12 @@ private void SetResizeCursor(Pointer pointer, Point pointerPosition)
11031100

11041101
if (this.OwningGrid.IsEnabled && (nearCurrentResizableColumnRightEdge || nearPreviousResizableColumnLeftEdge))
11051102
{
1106-
if (Window.Current != null)
1103+
CoreCursor currentCursor = CoreWindow.GetForCurrentThread().PointerCursor;
1104+
if (currentCursor != null && currentCursor.Type != CoreCursorType.SizeWestEast)
11071105
{
1108-
if (Window.Current.CoreWindow.PointerCursor != null && Window.Current.CoreWindow.PointerCursor.Type != CoreCursorType.SizeWestEast)
1109-
{
1110-
interactionInfo.OriginalCursor = Window.Current.CoreWindow.PointerCursor;
1111-
interactionInfo.ResizePointerId = pointer.PointerId;
1112-
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeWestEast, 0);
1113-
}
1106+
interactionInfo.OriginalCursor = currentCursor;
1107+
interactionInfo.ResizePointerId = pointer.PointerId;
1108+
CoreWindow.GetForCurrentThread().PointerCursor = new CoreCursor(CoreCursorType.SizeWestEast, 0);
11141109
}
11151110
}
11161111
else if (interactionInfo.ResizePointerId == pointer.PointerId)

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridRowHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private void DataGridRowHeader_Tapped(object sender, TappedRoutedEventArgs e)
432432
if (this.OwningRow != null)
433433
{
434434
Debug.Assert(sender is DataGridRowHeader, "Expected sender is DataGridRowHeader.");
435-
Debug.Assert(sender == this, "Expected sender is this.");
435+
Debug.Assert(sender as ContentControl == this, "Expected sender is this.");
436436

437437
e.Handled = this.OwningGrid.UpdateStateOnTapped(e, -1, this.Slot, false /*allowEdit*/);
438438
this.OwningGrid.UpdatedStateOnTapped = true;

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Utilities/KeyboardHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ internal static class KeyboardHelper
1212
{
1313
public static void GetMetaKeyState(out bool ctrl, out bool shift)
1414
{
15-
ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
16-
shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
15+
ctrl = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
16+
shift = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
1717
}
1818

1919
public static void GetMetaKeyState(out bool ctrl, out bool shift, out bool alt)
2020
{
2121
GetMetaKeyState(out ctrl, out shift);
22-
alt = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
22+
alt = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)