Skip to content

Commit 6394b50

Browse files
authored
Merge pull request #11 from w-ahmad/dev
merge dev branch into main
2 parents 3cb14af + 9d0a72c commit 6394b50

File tree

6 files changed

+86
-19
lines changed

6 files changed

+86
-19
lines changed

src/WinUI.TableView/TableView.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.UI;
55
using Microsoft.UI.Xaml;
66
using Microsoft.UI.Xaml.Controls;
7+
using Microsoft.UI.Xaml.Controls.Primitives;
78
using Microsoft.UI.Xaml.Data;
89
using Microsoft.UI.Xaml.Hosting;
910
using Microsoft.UI.Xaml.Input;
@@ -55,6 +56,8 @@ private void OnLoaded(object sender, RoutedEventArgs e)
5556
itemsPanelVisual.Clip = contentClip;
5657
contentClip.TopInset = (float)Math.Max(-scrollViewer.VerticalOffset, 0);
5758
contentClip.StartAnimation("TopInset", expressionClipAnimation);
59+
60+
UpdateVerticalScrollBarMargin();
5861
}
5962

6063
private bool Filter(object obj)
@@ -344,6 +347,11 @@ private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyC
344347
}
345348
}
346349

350+
private static void OnHeaderRowHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
351+
{
352+
(d as TableView)?.UpdateVerticalScrollBarMargin();
353+
}
354+
347355
private static void OnAutoGenerateColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
348356
{
349357
if (d is TableView tableView)
@@ -375,6 +383,18 @@ private static void OnCanFilterColumnsChanged(DependencyObject d, DependencyProp
375383
}
376384
}
377385

386+
private void UpdateVerticalScrollBarMargin()
387+
{
388+
if (GetTemplateChild("ScrollViewer") is ScrollViewer scrollViewer)
389+
{
390+
var verticalScrollBar = scrollViewer.FindDescendant<ScrollBar>(x => x.Name == "VerticalScrollBar");
391+
if (verticalScrollBar is not null)
392+
{
393+
verticalScrollBar.Margin = new Thickness(0, HeaderRowHeight, 0, 0);
394+
}
395+
}
396+
}
397+
378398
internal void ClearSorting()
379399
{
380400
CollectionView.SortDescriptions.Clear();
@@ -480,7 +500,7 @@ public bool CanFilterColumns
480500

481501
public static readonly new DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(IList), typeof(TableView), new PropertyMetadata(null, OnItemsSourceChanged));
482502
public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register(nameof(Columns), typeof(TableViewColumnsCollection), typeof(TableView), new PropertyMetadata(null));
483-
public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(48d));
503+
public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(32d, OnHeaderRowHeightChanged));
484504
public static readonly DependencyProperty RowHeightProperty = DependencyProperty.Register(nameof(RowHeight), typeof(double), typeof(TableView), new PropertyMetadata(40d));
485505
public static readonly DependencyProperty RowMaxHeightProperty = DependencyProperty.Register(nameof(RowMaxHeight), typeof(double), typeof(TableView), new PropertyMetadata(double.PositiveInfinity));
486506
public static readonly DependencyProperty ShowExportOptionsProperty = DependencyProperty.Register(nameof(ShowExportOptions), typeof(bool), typeof(TableView), new PropertyMetadata(false));

src/WinUI.TableView/TableViewCell.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using CommunityToolkit.WinUI;
2-
using Microsoft.UI.Input;
1+
using Microsoft.UI.Input;
32
using Microsoft.UI.Xaml;
43
using Microsoft.UI.Xaml.Controls;
54
using Microsoft.UI.Xaml.Input;
65
using Microsoft.UI.Xaml.Media;
76
using System;
87
using System.Linq;
98
using System.Threading.Tasks;
9+
using Windows.Foundation;
1010
using Windows.System;
1111
using Windows.UI.Core;
1212

@@ -22,6 +22,13 @@ public TableViewCell()
2222
DefaultStyleKey = typeof(TableViewCell);
2323
}
2424

25+
protected override Size MeasureOverride(Size availableSize)
26+
{
27+
var size = base.MeasureOverride(availableSize);
28+
Column.DesiredWidth = Math.Max(Column.DesiredWidth, size.Width);
29+
return size;
30+
}
31+
2532
protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e)
2633
{
2734
if (!IsReadOnly)

src/WinUI.TableView/TableViewColumn.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ private void EnsureHeaderStyle()
7272
}
7373
}
7474

75+
internal double DesiredWidth { get; set; }
76+
7577
public static readonly DependencyProperty HeaderStyleProperty = DependencyProperty.Register(nameof(HeaderStyle), typeof(Style), typeof(TableViewColumn), new PropertyMetadata(null, (d, _) => ((TableViewColumn)d).EnsureHeaderStyle()));
7678
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(object), typeof(TableViewColumn), new PropertyMetadata(null));
7779
public static readonly DependencyProperty WidthProperty = DependencyProperty.Register(nameof(Width), typeof(double), typeof(TableViewColumn), new PropertyMetadata(200d));

src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ private void InitializeCommands()
3939

4040
OkCommand.ExecuteRequested += delegate
4141
{
42-
SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList();
43-
ColumnHeader.ApplyFilter();
42+
ColumnHeader.HideFlyout();
43+
44+
if (ColumnHeader!._selectAllCheckBox!.IsChecked is true)
45+
{
46+
ColumnHeader.ClearFilter();
47+
}
48+
else
49+
{
50+
SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList();
51+
ColumnHeader.ApplyFilter();
52+
}
4453
};
4554

46-
CancelCommand.ExecuteRequested += delegate { ColumnHeader._optionsFlyout?.Hide(); };
55+
CancelCommand.ExecuteRequested += delegate { ColumnHeader.HideFlyout(); };
4756
}
4857

4958
public TableView TableView { get; }

src/WinUI.TableView/TableViewColumnHeader.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ private void ApplyFilter()
106106
return;
107107
}
108108

109-
_optionsFlyout?.Hide();
110109
_tableView.ActiveFilters[_propertyPath] = Filter;
111110
_tableView.CollectionView.RefreshFilter();
112111
IsFiltered = true;
113112
}
114113

114+
private void HideFlyout()
115+
{
116+
_optionsFlyout?.Hide();
117+
}
118+
115119
private bool Filter(object item)
116120
{
117121
var value = GetValue(item);
@@ -221,10 +225,9 @@ private void PrepareFilterItems(string? _filterText)
221225
{
222226
var value = GetValue(item);
223227
value = string.IsNullOrWhiteSpace(value?.ToString()) ? "(Blank)" : value;
224-
var isSelected = !string.IsNullOrEmpty(_filterText) ||
228+
var isSelected = !isFiltered || !string.IsNullOrEmpty(_filterText) ||
225229
(isFiltered && _optionsFlyoutViewModel.SelectedValues.Contains(value));
226230

227-
228231
return string.IsNullOrEmpty(_filterText)
229232
|| value?.ToString()?.Contains(_filterText, StringComparison.OrdinalIgnoreCase) == true
230233
? new FilterItem(isSelected, value, _optionsFlyoutViewModel)
@@ -291,9 +294,10 @@ private void SetFilterButtonVisibility()
291294

292295
private bool IsCursorInRightResizeArea(PointerRoutedEventArgs args)
293296
{
294-
var resizeArea = args.Pointer.PointerDeviceType == PointerDeviceType.Touch ? 8 : 4;
297+
var resizeWidth = args.Pointer.PointerDeviceType == PointerDeviceType.Touch ? 8 : 4;
295298
var point = args.GetCurrentPoint(this);
296-
return ActualWidth - point.Position.X <= resizeArea && point.Position.Y < ActualHeight - (_optionsButton?.ActualHeight ?? 0);
299+
var resizeHeight = ActualHeight - (CanFilter ? _optionsButton?.ActualHeight ?? 0 : 0);
300+
return ActualWidth - point.Position.X <= resizeWidth && point.Position.Y < resizeHeight;
297301
}
298302

299303
private bool IsCursorInLeftResizeArea(PointerRoutedEventArgs args)
@@ -303,6 +307,29 @@ private bool IsCursorInLeftResizeArea(PointerRoutedEventArgs args)
303307
return point.Position.X <= resizeArea && point.Position.Y < ActualHeight;
304308
}
305309

310+
protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e)
311+
{
312+
base.OnDoubleTapped(e);
313+
314+
if (IsSizingCursor && Column is not null)
315+
{
316+
var position = e.GetPosition(this);
317+
318+
if (position.X <= 8 && _headerRow?.GetPreviousHeader(this) is { Column: { } } header)
319+
{
320+
var width = Math.Clamp(header.Column.DesiredWidth, header.MinWidth, header.MaxWidth);
321+
header.Width = width;
322+
header.Measure(new Size(Width, ActualHeight));
323+
}
324+
else
325+
{
326+
var width = Math.Clamp(Column.DesiredWidth, MinWidth, MaxWidth);
327+
Width = width;
328+
Measure(new Size(Width, ActualHeight));
329+
}
330+
}
331+
}
332+
306333
protected override void OnPointerMoved(PointerRoutedEventArgs e)
307334
{
308335
base.OnPointerMoved(e);
@@ -348,7 +375,7 @@ protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e)
348375
}
349376
else if (_resizePreviousStarted && _headerRow?.GetPreviousHeader(this) is { } header)
350377
{
351-
header.Width = Math.Clamp(header.ActualWidth + e.Position.X, MinWidth, MaxWidth);
378+
header.Width = Math.Clamp(header.ActualWidth + e.Position.X, header.MinWidth, header.MaxWidth);
352379
header.Measure(new Size(header.Width, ActualHeight));
353380
}
354381
}

src/WinUI.TableView/Themes/TableViewColumnHeader.xaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@
195195
<MenuFlyoutItem>
196196
<MenuFlyoutItem.Template>
197197
<ControlTemplate TargetType="MenuFlyoutItem">
198-
<StackPanel Margin="8,4"
199-
Spacing="16"
200-
HorizontalAlignment="Right"
201-
Orientation="Horizontal">
202-
<Button Command="{Binding OkCommand}" />
203-
<Button Command="{Binding CancelCommand}" />
204-
</StackPanel>
198+
<Grid Margin="12,4"
199+
ColumnSpacing="16">
200+
<Grid.ColumnDefinitions>
201+
<ColumnDefinition Width="*" />
202+
<ColumnDefinition Width="*" />
203+
</Grid.ColumnDefinitions>
204+
<Button Command="{Binding OkCommand}" HorizontalAlignment="Stretch" Style="{StaticResource AccentButtonStyle}" />
205+
<Button Command="{Binding CancelCommand}" Grid.Column="1" HorizontalAlignment="Stretch" />
206+
</Grid>
205207
</ControlTemplate>
206208
</MenuFlyoutItem.Template>
207209
</MenuFlyoutItem>

0 commit comments

Comments
 (0)