Scroll bar size calculated based on content again, however with a min-size

This commit is contained in:
Peter Kirmeier 2023-08-20 22:38:28 +02:00
parent 5c021bf5e4
commit 892b89e0e2
3 changed files with 10 additions and 27 deletions

View file

@ -164,7 +164,7 @@
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" /> <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
</Track.DecreaseRepeatButton> </Track.DecreaseRepeatButton>
<Track.Thumb> <Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinHeight="10"> <Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
<Thumb.BorderBrush> <Thumb.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
@ -220,7 +220,7 @@
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" /> <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
</Track.DecreaseRepeatButton> </Track.DecreaseRepeatButton>
<Track.Thumb> <Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinWidth="10"> <Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
<Thumb.BorderBrush> <Thumb.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops> <LinearGradientBrush.GradientStops>

View file

@ -184,6 +184,11 @@
SelectionChanged="ListView_SelectionChanged" MouseLeave="ListView_MouseLeave" SelectionChanged="ListView_SelectionChanged" MouseLeave="ListView_MouseLeave"
ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.ScrollChanged="HandleScrollChanged"> ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.ScrollChanged="HandleScrollChanged">
<!--ListView."Childs".Border.Padding="0" // In ctor, see: dgv_border --> <!--ListView."Childs".Border.Padding="0" // In ctor, see: dgv_border -->
<ListView.Resources>
<!-- Set min-size according to: learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-customize-the-thumb-size-on-a-scrollbar#create-a-scrollbar-with-a-minimum-thumb-size -->
<!-- Thumb's minimum height is half of VerticalScrollBarButtonHeightKey -->
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarButtonHeightKey}">116</sys:Double>
</ListView.Resources>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border Height="{DynamicResource RowHeight}" BorderBrush="{Binding BorderBrush}" Background="{Binding BackgroundBrush}" BorderThickness="1"> <Border Height="{DynamicResource RowHeight}" BorderBrush="{Binding BorderBrush}" Background="{Binding BackgroundBrush}" BorderThickness="1">

View file

@ -592,15 +592,15 @@ namespace SystemTrayMenu.UserInterface
if (IsLoaded) if (IsLoaded)
{ {
AdjustWindowPositionAndInnerLayoutInternal(originLocation); AdjustWindowPositionInternal(originLocation);
} }
else else
{ {
// Layout cannot be calculated during loading, postpone this event // Layout cannot be calculated during loading, postpone this event
Loaded += (_, _) => AdjustWindowPositionAndInnerLayoutInternal(originLocation); Loaded += (_, _) => AdjustWindowPositionInternal(originLocation);
} }
void AdjustWindowPositionAndInnerLayoutInternal(in Point originLocation) void AdjustWindowPositionInternal(in Point originLocation)
{ {
double scaling = Math.Round(Scaling.Factor, 0, MidpointRounding.AwayFromZero); double scaling = Math.Round(Scaling.Factor, 0, MidpointRounding.AwayFromZero);
double overlappingOffset = 0D; double overlappingOffset = 0D;
@ -846,29 +846,7 @@ namespace SystemTrayMenu.UserInterface
windowFrame.CornerRadius = new CornerRadius(CornerRadius); windowFrame.CornerRadius = new CornerRadius(CornerRadius);
} }
// Make sure we have latest values of all control sizes
UpdateLayout(); UpdateLayout();
// Adjust size of scroll bar thumb
// See: https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-customize-the-thumb-size-on-a-scrollbar?view=netframeworkdesktop-4.8#create-a-scrollbar-with-a-fixed-thumb-size
ScrollBar? dgvSrollBar = dgv.FindVisualChildOfType<ScrollBar>(0);
if (dgvSrollBar != null)
{
Track? dgvSrollBarTrack = dgvSrollBar.FindVisualChildOfType<Track>(0);
if (dgvSrollBarTrack != null)
{
RepeatButton? dgvSrollBarLineButton = dgvSrollBar.FindVisualChildOfType<RepeatButton>(0);
Thumb? dgvSrollBarThumb = dgvSrollBarTrack.FindVisualChildOfType<Thumb>(0);
if (dgvSrollBarLineButton != null && dgvSrollBarThumb != null)
{
// Disable auto resizing
dgvSrollBarTrack.ViewportSize = double.NaN;
// We set the thumb size of the scroll bar to 25% of the thumbs space but at least to 10
dgvSrollBarThumb.Height = (dgv.ActualHeight - (dgvSrollBarLineButton.ActualHeight * 2)) * 0.25d;
}
}
}
} }
} }