diff --git a/src/WinUI.TableView/TableView.cs b/src/WinUI.TableView/TableView.cs index 4a34a92..e9c5502 100644 --- a/src/WinUI.TableView/TableView.cs +++ b/src/WinUI.TableView/TableView.cs @@ -127,7 +127,6 @@ protected override void OnPreviewKeyDown(KeyRoutedEventArgs e) if (isEditing && currentCell is not null) { - currentCell.SetElement(); currentCell = GetCellFromSlot(newSlot); currentCell.PrepareForEdit(); } @@ -655,9 +654,10 @@ internal async void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrl SelectedCellRanges.Remove(selectionRange); selectionRange.Clear(); SelectionStartCellSlot ??= CurrentCellSlot; + SelectionStartCellSlot ??= slot; if (shiftKey && SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended) { - var currentSlot = SelectionStartCellSlot ?? slot; + var currentSlot = SelectionStartCellSlot.Value; var startRow = Math.Min(slot.Row, currentSlot.Row); var endRow = Math.Max(slot.Row, currentSlot.Row); var startCol = Math.Min(slot.Column, currentSlot.Column); @@ -677,7 +677,7 @@ internal async void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrl } else { - SelectionStartCellSlot = null; + SelectionStartCellSlot = slot; selectionRange.Add(slot); if (SelectedCellRanges.LastOrDefault(x => x.Contains(slot)) is { } range) @@ -713,6 +713,8 @@ internal void DeselectCell(TableViewCellSlot slot) internal void SetCurrentCell(TableViewCellSlot? slot) { var oldSlot = CurrentCellSlot; + var currentCell = oldSlot.HasValue ? GetCellFromSlot(oldSlot.Value) : default; + currentCell?.SetElement(); CurrentCellSlot = slot; CurrentCellChanged?.Invoke(this, new TableViewCurrentCellChangedEventArgs(oldSlot, slot)); } @@ -832,7 +834,7 @@ void ViewChanged(object? _, ScrollViewerViewChangedEventArgs e) return default; } - private TableViewCell GetCellFromSlot(TableViewCellSlot slot) + internal TableViewCell GetCellFromSlot(TableViewCellSlot slot) { return ContainerFromIndex(slot.Row) is TableViewRow row ? row.Cells[slot.Column] : default!; } diff --git a/src/WinUI.TableView/TableViewCell.cs b/src/WinUI.TableView/TableViewCell.cs index c045aa0..97948e7 100644 --- a/src/WinUI.TableView/TableViewCell.cs +++ b/src/WinUI.TableView/TableViewCell.cs @@ -82,8 +82,6 @@ protected override void OnPointerPressed(PointerRoutedEventArgs e) { TableView.SelectionStartCellSlot = Slot; } - - e.Handled = TableView.SelectionUnit != TableViewSelectionUnit.Row; } protected override void OnPointerReleased(PointerRoutedEventArgs e) @@ -94,6 +92,8 @@ protected override void OnPointerReleased(PointerRoutedEventArgs e) { TableView.SelectionStartCellSlot = null; } + + e.Handled = TableView.SelectionUnit != TableViewSelectionUnit.Row; } protected override void OnPointerMoved(PointerRoutedEventArgs e) diff --git a/src/WinUI.TableView/TableViewRow.cs b/src/WinUI.TableView/TableViewRow.cs index 627cfb8..133d33b 100644 --- a/src/WinUI.TableView/TableViewRow.cs +++ b/src/WinUI.TableView/TableViewRow.cs @@ -1,6 +1,5 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -10,7 +9,6 @@ namespace WinUI.TableView; public class TableViewRow : ListViewItem { private TableViewCellPresenter? _cellPresenter; - private ListViewItemPresenter _itemPresenter = null!; public TableViewRow() { @@ -18,13 +16,6 @@ public TableViewRow() SizeChanged += OnSizeChanged; } - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - _itemPresenter = (ListViewItemPresenter)GetTemplateChild("Root"); - } - protected override void OnContentChanged(object oldContent, object newContent) { if (TableView is null) diff --git a/src/WinUI.TableView/Themes/TableView.xaml b/src/WinUI.TableView/Themes/TableView.xaml index 41551ce..1e088a2 100644 --- a/src/WinUI.TableView/Themes/TableView.xaml +++ b/src/WinUI.TableView/Themes/TableView.xaml @@ -41,6 +41,8 @@ Value="{ThemeResource TableViewGridLinesBrush}" /> +