Skip to content

Commit 9070ba6

Browse files
committed
fixing up selection behavior based on selection modes
1 parent e388865 commit 9070ba6

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

src/WinUI.TableView/TableView.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ protected override void OnPreviewKeyDown(KeyRoutedEventArgs e)
127127

128128
if (isEditing && currentCell is not null)
129129
{
130-
currentCell.SetElement();
131130
currentCell = GetCellFromSlot(newSlot);
132131
currentCell.PrepareForEdit();
133132
}
@@ -655,9 +654,10 @@ internal async void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrl
655654
SelectedCellRanges.Remove(selectionRange);
656655
selectionRange.Clear();
657656
SelectionStartCellSlot ??= CurrentCellSlot;
657+
SelectionStartCellSlot ??= slot;
658658
if (shiftKey && SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended)
659659
{
660-
var currentSlot = SelectionStartCellSlot ?? slot;
660+
var currentSlot = SelectionStartCellSlot.Value;
661661
var startRow = Math.Min(slot.Row, currentSlot.Row);
662662
var endRow = Math.Max(slot.Row, currentSlot.Row);
663663
var startCol = Math.Min(slot.Column, currentSlot.Column);
@@ -677,7 +677,7 @@ internal async void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrl
677677
}
678678
else
679679
{
680-
SelectionStartCellSlot = null;
680+
SelectionStartCellSlot = slot;
681681
selectionRange.Add(slot);
682682

683683
if (SelectedCellRanges.LastOrDefault(x => x.Contains(slot)) is { } range)
@@ -713,6 +713,8 @@ internal void DeselectCell(TableViewCellSlot slot)
713713
internal void SetCurrentCell(TableViewCellSlot? slot)
714714
{
715715
var oldSlot = CurrentCellSlot;
716+
var currentCell = oldSlot.HasValue ? GetCellFromSlot(oldSlot.Value) : default;
717+
currentCell?.SetElement();
716718
CurrentCellSlot = slot;
717719
CurrentCellChanged?.Invoke(this, new TableViewCurrentCellChangedEventArgs(oldSlot, slot));
718720
}
@@ -832,7 +834,7 @@ void ViewChanged(object? _, ScrollViewerViewChangedEventArgs e)
832834
return default;
833835
}
834836

835-
private TableViewCell GetCellFromSlot(TableViewCellSlot slot)
837+
internal TableViewCell GetCellFromSlot(TableViewCellSlot slot)
836838
{
837839
return ContainerFromIndex(slot.Row) is TableViewRow row ? row.Cells[slot.Column] : default!;
838840
}

src/WinUI.TableView/TableViewCell.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ protected override void OnPointerPressed(PointerRoutedEventArgs e)
8282
{
8383
TableView.SelectionStartCellSlot = Slot;
8484
}
85-
86-
e.Handled = TableView.SelectionUnit != TableViewSelectionUnit.Row;
8785
}
8886

8987
protected override void OnPointerReleased(PointerRoutedEventArgs e)
@@ -94,6 +92,8 @@ protected override void OnPointerReleased(PointerRoutedEventArgs e)
9492
{
9593
TableView.SelectionStartCellSlot = null;
9694
}
95+
96+
e.Handled = TableView.SelectionUnit != TableViewSelectionUnit.Row;
9797
}
9898

9999
protected override void OnPointerMoved(PointerRoutedEventArgs e)

src/WinUI.TableView/TableViewRow.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.UI.Xaml;
22
using Microsoft.UI.Xaml.Controls;
3-
using Microsoft.UI.Xaml.Controls.Primitives;
43
using System;
54
using System.Collections.Generic;
65
using System.Collections.Specialized;
@@ -10,21 +9,13 @@ namespace WinUI.TableView;
109
public class TableViewRow : ListViewItem
1110
{
1211
private TableViewCellPresenter? _cellPresenter;
13-
private ListViewItemPresenter _itemPresenter = null!;
1412

1513
public TableViewRow()
1614
{
1715
DefaultStyleKey = typeof(TableViewRow);
1816
SizeChanged += OnSizeChanged;
1917
}
2018

21-
protected override void OnApplyTemplate()
22-
{
23-
base.OnApplyTemplate();
24-
25-
_itemPresenter = (ListViewItemPresenter)GetTemplateChild("Root");
26-
}
27-
2819
protected override void OnContentChanged(object oldContent, object newContent)
2920
{
3021
if (TableView is null)

src/WinUI.TableView/Themes/TableView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
Value="{ThemeResource TableViewGridLinesBrush}" />
4242
<Setter Property="BorderThickness"
4343
Value="1" />
44+
<Setter Property="SingleSelectionFollowsFocus"
45+
Value="False" />
4446
<Setter Property="ItemContainerTransitions">
4547
<Setter.Value>
4648
<TransitionCollection>

0 commit comments

Comments
 (0)