Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Bugfix for showing last control (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Apr 1, 2024
1 parent b5bd939 commit a2d55c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
25 changes: 3 additions & 22 deletions src/BIOSBuddy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,30 +800,10 @@ private void ShowVersionInfo()
}
}

private bool IsUserControlVisibleInScrollViewer(UserControl userControl, ScrollViewer scrollViewer)
{
// Get the bounds of the UserControl
var controlBounds = userControl.TransformToAncestor(scrollViewer)
.TransformBounds(new Rect(0.0, 0.0, userControl.ActualWidth, userControl.ActualHeight));

// Get the visible region of the ScrollViewer
var visibleRegion = new Rect(scrollViewer.HorizontalOffset, scrollViewer.VerticalOffset, scrollViewer.ViewportWidth, scrollViewer.ViewportHeight);

// Check if the UserControl is within the visible region of the ScrollViewer
return visibleRegion.IntersectsWith(controlBounds);
}

private void SaveVisibleUserControl()
{
foreach (UserControl userControl in ItemsControlControls.Items)
{
if (!IsUserControlVisibleInScrollViewer(userControl, ScrollViewerControls)) continue;

Settings.Default.ScrollViewerVerticalOffset = ScrollViewerControls.VerticalOffset;
Settings.Default.Save();

break;
}
Settings.Default.ScrollViewerVerticalOffset = ScrollViewerControls.VerticalOffset;
Settings.Default.Save();
}

private void ScrollViewerControls_OnLoaded(object sender, RoutedEventArgs e)
Expand All @@ -834,6 +814,7 @@ private void ScrollViewerControls_OnLoaded(object sender, RoutedEventArgs e)

ItemsControlControls.UpdateLayout();
ScrollViewerControls.UpdateLayout();

if (Settings.Default.ScrollViewerVerticalOffset < ScrollViewerControls.ScrollableHeight)
{
ScrollViewerControls.ScrollToVerticalOffset(Settings.Default.ScrollViewerVerticalOffset);
Expand Down

0 comments on commit a2d55c9

Please sign in to comment.