Skip to content

Commit 3200ef8

Browse files
committed
make the vertical scrollbar to display under the header row
1 parent 88c8160 commit 3200ef8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
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(32d));
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));

0 commit comments

Comments
 (0)