mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-06 06:51:04 +12:00
Scroll bar size calculated based on content again, however with a min-size
This commit is contained in:
parent
5c021bf5e4
commit
892b89e0e2
|
@ -164,7 +164,7 @@
|
|||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinHeight="10">
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
|
||||
<Thumb.BorderBrush>
|
||||
|
||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
||||
|
@ -220,7 +220,7 @@
|
|||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinWidth="10">
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
|
||||
<Thumb.BorderBrush>
|
||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
||||
<LinearGradientBrush.GradientStops>
|
||||
|
|
|
@ -184,6 +184,11 @@
|
|||
SelectionChanged="ListView_SelectionChanged" MouseLeave="ListView_MouseLeave"
|
||||
ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.ScrollChanged="HandleScrollChanged">
|
||||
<!--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>
|
||||
<DataTemplate>
|
||||
<Border Height="{DynamicResource RowHeight}" BorderBrush="{Binding BorderBrush}" Background="{Binding BackgroundBrush}" BorderThickness="1">
|
||||
|
|
|
@ -592,15 +592,15 @@ namespace SystemTrayMenu.UserInterface
|
|||
|
||||
if (IsLoaded)
|
||||
{
|
||||
AdjustWindowPositionAndInnerLayoutInternal(originLocation);
|
||||
AdjustWindowPositionInternal(originLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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 overlappingOffset = 0D;
|
||||
|
@ -846,29 +846,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
windowFrame.CornerRadius = new CornerRadius(CornerRadius);
|
||||
}
|
||||
|
||||
// Make sure we have latest values of all control sizes
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue