Skip to content

Commit b10db78

Browse files
authored
Merge pull request #184 from w-ahmad/HeaderRowSizing
added HeaderRowMin & Max properties
2 parents 711f30c + 70694a9 commit b10db78

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/TableView.Properties.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ public partial class TableView
2828
/// <summary>
2929
/// Identifies the HeaderRowHeight dependency property.
3030
/// </summary>
31-
public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(32d, OnHeaderRowHeightChanged));
31+
public static readonly DependencyProperty HeaderRowHeightProperty = DependencyProperty.Register(nameof(HeaderRowHeight), typeof(double), typeof(TableView), new PropertyMetadata(double.NaN, OnHeaderRowHeightChanged));
32+
33+
/// <summary>
34+
/// Identifies the HeaderRowMaxHeight dependency property.
35+
/// </summary>
36+
public static readonly DependencyProperty HeaderRowMaxHeightProperty = DependencyProperty.Register(nameof(HeaderRowMaxHeight), typeof(double), typeof(TableView), new PropertyMetadata(double.PositiveInfinity, OnHeaderRowHeightChanged));
37+
38+
/// <summary>
39+
/// Identifies the HeaderRowMinHeight dependency property.
40+
/// </summary>
41+
public static readonly DependencyProperty HeaderRowMinHeightProperty = DependencyProperty.Register(nameof(HeaderRowMinHeight), typeof(double), typeof(TableView), new PropertyMetadata(32d, OnHeaderRowHeightChanged));
3242

3343
/// <summary>
3444
/// Identifies the RowHeight dependency property.
@@ -252,6 +262,24 @@ public double HeaderRowHeight
252262
set => SetValue(HeaderRowHeightProperty, value);
253263
}
254264

265+
/// <summary>
266+
/// Gets or sets the max height of the header row.
267+
/// </summary>
268+
public double HeaderRowMaxHeight
269+
{
270+
get => (double)GetValue(HeaderRowMaxHeightProperty);
271+
set => SetValue(HeaderRowMaxHeightProperty, value);
272+
}
273+
274+
/// <summary>
275+
/// Gets or sets the min height of the header row.
276+
/// </summary>
277+
public double HeaderRowMinHeight
278+
{
279+
get => (double)GetValue(HeaderRowMinHeightProperty);
280+
set => SetValue(HeaderRowMinHeightProperty, value);
281+
}
282+
255283
/// <summary>
256284
/// Gets or sets the height of the rows.
257285
/// </summary>

src/TableView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ private void UpdateVerticalScrollBarMargin()
753753
var verticalScrollBar = scrollViewer.FindDescendant<ScrollBar>(x => x.Name == "VerticalScrollBar");
754754
if (verticalScrollBar is not null)
755755
{
756-
verticalScrollBar.Margin = new Thickness(0, HeaderRowHeight, 0, 0);
756+
verticalScrollBar.Margin = new Thickness(0, _headerRow?.ActualHeight ?? 0, 0, 0);
757757
}
758758
}
759759
}

src/TableViewHeaderRow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ internal void CalculateHeaderWidths()
230230
var autoColumns = allColumns.Where(x => x.Width.IsAuto).ToList();
231231
var absoluteColumns = allColumns.Where(x => x.Width.IsAbsolute).ToList();
232232

233-
var height = TableView.HeaderRowHeight;
233+
var height = ActualHeight;
234234
var availableWidth = TableView.ActualWidth - 32;
235235
var starUnitWeight = starColumns.Select(x => x.Width.Value).Sum();
236236
var fixedWidth = autoColumns.Select(x =>
@@ -300,7 +300,7 @@ internal void CalculateHeaderWidths()
300300
DispatcherQueue.TryEnqueue(() =>
301301
header.Measure(
302302
new Size(header.Width,
303-
_headersStackPanel?.ActualHeight ?? TableView.HeaderRowHeight)));
303+
_headersStackPanel?.ActualHeight ?? ActualHeight)));
304304
}
305305
}
306306

src/Themes/TableView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
<local:TableViewHeaderRow x:Name="HeaderRow"
104104
IsTabStop="False"
105105
Height="{TemplateBinding HeaderRowHeight}"
106+
MaxHeight="{TemplateBinding HeaderRowMaxHeight}"
107+
MinHeight="{TemplateBinding HeaderRowMinHeight}"
106108
TableView="{Binding RelativeSource={RelativeSource TemplatedParent}}">
107109
<interactivity:Interaction.Behaviors>
108110
<behaviors:StickyHeaderBehavior />

src/Themes/TableViewHeaderRow.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
<Style x:Key="DefaultTableViewHeaderRowStyle"
1010
TargetType="local:TableViewHeaderRow">
11-
<Setter Property="Height"
12-
Value="32" />
1311
<Setter Property="Background"
1412
Value="{ThemeResource TableViewHeaderRowBackground}" />
1513
<Setter Property="Template">

0 commit comments

Comments
 (0)