mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-02 01:57:23 +13:00
Set thumb sizes of menu scroll bars to 25 percent of their scroll-able height
This commit is contained in:
parent
4b5e75180c
commit
cfd53b516e
2 changed files with 28 additions and 5 deletions
|
@ -165,7 +165,7 @@
|
|||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinHeight="10">
|
||||
<Thumb.BorderBrush>
|
||||
|
||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
||||
|
@ -221,7 +221,7 @@
|
|||
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
|
||||
</Track.DecreaseRepeatButton>
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0">
|
||||
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0" MinWidth="10">
|
||||
<Thumb.BorderBrush>
|
||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
||||
<LinearGradientBrush.GradientStops>
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
@ -558,15 +559,15 @@ namespace SystemTrayMenu.UserInterface
|
|||
|
||||
if (IsLoaded)
|
||||
{
|
||||
AdjustWindowPositionInternal(originLocation);
|
||||
AdjustWindowPositionAndInnerLayoutInternal(originLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Layout cannot be calculated during loading, postpone this event
|
||||
Loaded += (_, _) => AdjustWindowPositionInternal(originLocation);
|
||||
Loaded += (_, _) => AdjustWindowPositionAndInnerLayoutInternal(originLocation);
|
||||
}
|
||||
|
||||
void AdjustWindowPositionInternal(in Point originLocation)
|
||||
void AdjustWindowPositionAndInnerLayoutInternal(in Point originLocation)
|
||||
{
|
||||
double scaling = Math.Round(Scaling.Factor, 0, MidpointRounding.AwayFromZero);
|
||||
double overlappingOffset = 0D;
|
||||
|
@ -810,7 +811,29 @@ 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