From 892b89e0e285d31ee32f6b1456fe517070b6d81a Mon Sep 17 00:00:00 2001 From: Peter Kirmeier Date: Sun, 20 Aug 2023 22:38:28 +0200 Subject: [PATCH] Scroll bar size calculated based on content again, however with a min-size --- Resources/ScrollBarStyles.xaml | 4 ++-- UserInterface/Menu.xaml | 5 +++++ UserInterface/Menu.xaml.cs | 28 +++------------------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Resources/ScrollBarStyles.xaml b/Resources/ScrollBarStyles.xaml index eb18ae5..af4f356 100644 --- a/Resources/ScrollBarStyles.xaml +++ b/Resources/ScrollBarStyles.xaml @@ -164,7 +164,7 @@ - + @@ -220,7 +220,7 @@ - + diff --git a/UserInterface/Menu.xaml b/UserInterface/Menu.xaml index cf6b32a..bd72c13 100644 --- a/UserInterface/Menu.xaml +++ b/UserInterface/Menu.xaml @@ -184,6 +184,11 @@ SelectionChanged="ListView_SelectionChanged" MouseLeave="ListView_MouseLeave" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.ScrollChanged="HandleScrollChanged"> + + + + 116 + diff --git a/UserInterface/Menu.xaml.cs b/UserInterface/Menu.xaml.cs index ceb5fc0..a014705 100644 --- a/UserInterface/Menu.xaml.cs +++ b/UserInterface/Menu.xaml.cs @@ -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(0); - if (dgvSrollBar != null) - { - Track? dgvSrollBarTrack = dgvSrollBar.FindVisualChildOfType(0); - if (dgvSrollBarTrack != null) - { - RepeatButton? dgvSrollBarLineButton = dgvSrollBar.FindVisualChildOfType(0); - Thumb? dgvSrollBarThumb = dgvSrollBarTrack.FindVisualChildOfType(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; - } - } - } } }