diff --git a/src/WinUI.TableView/TableView.cs b/src/WinUI.TableView/TableView.cs index 4fef718..dd72935 100644 --- a/src/WinUI.TableView/TableView.cs +++ b/src/WinUI.TableView/TableView.cs @@ -4,6 +4,7 @@ using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Hosting; using Microsoft.UI.Xaml.Input; @@ -55,6 +56,8 @@ private void OnLoaded(object sender, RoutedEventArgs e) itemsPanelVisual.Clip = contentClip; contentClip.TopInset = (float)Math.Max(-scrollViewer.VerticalOffset, 0); contentClip.StartAnimation("TopInset", expressionClipAnimation); + + UpdateVerticalScrollBarMargin(); } private bool Filter(object obj) @@ -344,6 +347,11 @@ private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyC } } + private static void OnHeaderRowHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as TableView)?.UpdateVerticalScrollBarMargin(); + } + private static void OnAutoGenerateColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is TableView tableView) @@ -375,6 +383,18 @@ private static void OnCanFilterColumnsChanged(DependencyObject d, DependencyProp } } + private void UpdateVerticalScrollBarMargin() + { + if (GetTemplateChild("ScrollViewer") is ScrollViewer scrollViewer) + { + var verticalScrollBar = scrollViewer.FindDescendant(x => x.Name == "VerticalScrollBar"); + if (verticalScrollBar is not null) + { + verticalScrollBar.Margin = new Thickness(0, HeaderRowHeight, 0, 0); + } + } + } + internal void ClearSorting() { CollectionView.SortDescriptions.Clear(); @@ -480,7 +500,7 @@ public bool CanFilterColumns public static readonly new DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(IList), typeof(TableView), new PropertyMetadata(null, OnItemsSourceChanged)); public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register(nameof(Columns), typeof(TableViewColumnsCollection), typeof(TableView), new PropertyMetadata(null)); - public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(48d)); + public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(32d, OnHeaderRowHeightChanged)); public static readonly DependencyProperty RowHeightProperty = DependencyProperty.Register(nameof(RowHeight), typeof(double), typeof(TableView), new PropertyMetadata(40d)); public static readonly DependencyProperty RowMaxHeightProperty = DependencyProperty.Register(nameof(RowMaxHeight), typeof(double), typeof(TableView), new PropertyMetadata(double.PositiveInfinity)); public static readonly DependencyProperty ShowExportOptionsProperty = DependencyProperty.Register(nameof(ShowExportOptions), typeof(bool), typeof(TableView), new PropertyMetadata(false)); diff --git a/src/WinUI.TableView/TableViewCell.cs b/src/WinUI.TableView/TableViewCell.cs index b680e38..876f39c 100644 --- a/src/WinUI.TableView/TableViewCell.cs +++ b/src/WinUI.TableView/TableViewCell.cs @@ -1,5 +1,4 @@ -using CommunityToolkit.WinUI; -using Microsoft.UI.Input; +using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; @@ -7,6 +6,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using Windows.Foundation; using Windows.System; using Windows.UI.Core; @@ -22,6 +22,13 @@ public TableViewCell() DefaultStyleKey = typeof(TableViewCell); } + protected override Size MeasureOverride(Size availableSize) + { + var size = base.MeasureOverride(availableSize); + Column.DesiredWidth = Math.Max(Column.DesiredWidth, size.Width); + return size; + } + protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e) { if (!IsReadOnly) diff --git a/src/WinUI.TableView/TableViewColumn.cs b/src/WinUI.TableView/TableViewColumn.cs index cd8506b..40c8a2c 100644 --- a/src/WinUI.TableView/TableViewColumn.cs +++ b/src/WinUI.TableView/TableViewColumn.cs @@ -72,6 +72,8 @@ private void EnsureHeaderStyle() } } + internal double DesiredWidth { get; set; } + public static readonly DependencyProperty HeaderStyleProperty = DependencyProperty.Register(nameof(HeaderStyle), typeof(Style), typeof(TableViewColumn), new PropertyMetadata(null, (d, _) => ((TableViewColumn)d).EnsureHeaderStyle())); public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(object), typeof(TableViewColumn), new PropertyMetadata(null)); public static readonly DependencyProperty WidthProperty = DependencyProperty.Register(nameof(Width), typeof(double), typeof(TableViewColumn), new PropertyMetadata(200d)); diff --git a/src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs b/src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs index 3736a79..d22170c 100644 --- a/src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs +++ b/src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs @@ -39,11 +39,20 @@ private void InitializeCommands() OkCommand.ExecuteRequested += delegate { - SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList(); - ColumnHeader.ApplyFilter(); + ColumnHeader.HideFlyout(); + + if (ColumnHeader!._selectAllCheckBox!.IsChecked is true) + { + ColumnHeader.ClearFilter(); + } + else + { + SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList(); + ColumnHeader.ApplyFilter(); + } }; - CancelCommand.ExecuteRequested += delegate { ColumnHeader._optionsFlyout?.Hide(); }; + CancelCommand.ExecuteRequested += delegate { ColumnHeader.HideFlyout(); }; } public TableView TableView { get; } diff --git a/src/WinUI.TableView/TableViewColumnHeader.cs b/src/WinUI.TableView/TableViewColumnHeader.cs index 801bd06..8808a9e 100644 --- a/src/WinUI.TableView/TableViewColumnHeader.cs +++ b/src/WinUI.TableView/TableViewColumnHeader.cs @@ -106,12 +106,16 @@ private void ApplyFilter() return; } - _optionsFlyout?.Hide(); _tableView.ActiveFilters[_propertyPath] = Filter; _tableView.CollectionView.RefreshFilter(); IsFiltered = true; } + private void HideFlyout() + { + _optionsFlyout?.Hide(); + } + private bool Filter(object item) { var value = GetValue(item); @@ -221,10 +225,9 @@ private void PrepareFilterItems(string? _filterText) { var value = GetValue(item); value = string.IsNullOrWhiteSpace(value?.ToString()) ? "(Blank)" : value; - var isSelected = !string.IsNullOrEmpty(_filterText) || + var isSelected = !isFiltered || !string.IsNullOrEmpty(_filterText) || (isFiltered && _optionsFlyoutViewModel.SelectedValues.Contains(value)); - return string.IsNullOrEmpty(_filterText) || value?.ToString()?.Contains(_filterText, StringComparison.OrdinalIgnoreCase) == true ? new FilterItem(isSelected, value, _optionsFlyoutViewModel) @@ -291,9 +294,10 @@ private void SetFilterButtonVisibility() private bool IsCursorInRightResizeArea(PointerRoutedEventArgs args) { - var resizeArea = args.Pointer.PointerDeviceType == PointerDeviceType.Touch ? 8 : 4; + var resizeWidth = args.Pointer.PointerDeviceType == PointerDeviceType.Touch ? 8 : 4; var point = args.GetCurrentPoint(this); - return ActualWidth - point.Position.X <= resizeArea && point.Position.Y < ActualHeight - (_optionsButton?.ActualHeight ?? 0); + var resizeHeight = ActualHeight - (CanFilter ? _optionsButton?.ActualHeight ?? 0 : 0); + return ActualWidth - point.Position.X <= resizeWidth && point.Position.Y < resizeHeight; } private bool IsCursorInLeftResizeArea(PointerRoutedEventArgs args) @@ -303,6 +307,29 @@ private bool IsCursorInLeftResizeArea(PointerRoutedEventArgs args) return point.Position.X <= resizeArea && point.Position.Y < ActualHeight; } + protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e) + { + base.OnDoubleTapped(e); + + if (IsSizingCursor && Column is not null) + { + var position = e.GetPosition(this); + + if (position.X <= 8 && _headerRow?.GetPreviousHeader(this) is { Column: { } } header) + { + var width = Math.Clamp(header.Column.DesiredWidth, header.MinWidth, header.MaxWidth); + header.Width = width; + header.Measure(new Size(Width, ActualHeight)); + } + else + { + var width = Math.Clamp(Column.DesiredWidth, MinWidth, MaxWidth); + Width = width; + Measure(new Size(Width, ActualHeight)); + } + } + } + protected override void OnPointerMoved(PointerRoutedEventArgs e) { base.OnPointerMoved(e); @@ -348,7 +375,7 @@ protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) } else if (_resizePreviousStarted && _headerRow?.GetPreviousHeader(this) is { } header) { - header.Width = Math.Clamp(header.ActualWidth + e.Position.X, MinWidth, MaxWidth); + header.Width = Math.Clamp(header.ActualWidth + e.Position.X, header.MinWidth, header.MaxWidth); header.Measure(new Size(header.Width, ActualHeight)); } } diff --git a/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml b/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml index 168f5b0..5edc30d 100644 --- a/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml +++ b/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml @@ -195,13 +195,15 @@ - -