Skip to content

Commit

Permalink
fixed horizontal PageChanged on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-vov committed Oct 7, 2024
1 parent dd9d672 commit 3cacc7b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Maui.PDFView/Platforms/Windows/PdfViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,32 @@ private void OnScrollViewerViewChanged(object sender, ScrollViewerViewChangedEve

for (int i = 0; i < layout.Children.Count; i++)
{
var child = layout.Children[i] as UIElement;
var child = layout.Children[i] as FrameworkElement;
if (child != null)
{
var transform = child.TransformToVisual(_scrollViewer);
var position = transform.TransformBounds(new(0, 0, 1, 1));
var position = transform.TransformBounds(new(0, 0, child.ActualWidth, child.ActualHeight));

// Determine if the child is visible in the viewport
if (position.Bottom >= 0 && position.Top <= _scrollViewer.ViewportHeight)
// Check visibility based on the scrolling direction
bool isVisible = VirtualView.IsHorizontal
? (position.Right >= 0 && position.Left <= _scrollViewer.ViewportWidth)
: (position.Bottom >= 0 && position.Top <= _scrollViewer.ViewportHeight);

if (isVisible)
{
var visibleSize = position.Height;
// Calculate visible size based on the layout orientation
double visibleSize = VirtualView.IsHorizontal
? Math.Min(position.Right, _scrollViewer.ViewportWidth) - Math.Max(position.Left, 0)
: Math.Min(position.Bottom, _scrollViewer.ViewportHeight) - Math.Max(position.Top, 0);

if (visibleSize > maxVisibleSize)
{
maxVisibleSize = visibleSize;
currentPage = i;
}
}
}

}

if (currentPage >= 0 && VirtualView.PageChangedCommand?.CanExecute(null) == true)
Expand Down

0 comments on commit 3cacc7b

Please sign in to comment.