NavigationPageScrollAwarePage.xaml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <UserControl xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. x:Class="ControlCatalog.Pages.NavigationPageScrollAwarePage">
  4. <Panel ClipToBounds="True">
  5. <!-- Reserve right column so the NavigationPage does not go under the info panel -->
  6. <Grid ColumnDefinitions="*, 260">
  7. <Border Grid.Column="0" Margin="12"
  8. BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
  9. BorderThickness="1" CornerRadius="6" ClipToBounds="True">
  10. <NavigationPage x:Name="DemoNav" />
  11. </Border>
  12. </Grid>
  13. <!-- Info panel: fixed 260 px wide, floats over the right edge, scrollable internally -->
  14. <Border Width="260" HorizontalAlignment="Right"
  15. BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
  16. BorderThickness="1,0,0,0"
  17. Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}">
  18. <ScrollViewer>
  19. <StackPanel Margin="12" Spacing="8">
  20. <TextBlock Text="How it works" FontWeight="SemiBold" FontSize="16"
  21. Foreground="{DynamicResource SystemControlHighlightAccentBrush}" />
  22. <TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.7"
  23. Text="The navigation bar hides on downward scroll and reappears on upward scroll. The pattern is built entirely with existing public API." />
  24. <Separator />
  25. <TextBlock Text="Step 1: Overlay mode" FontSize="13" FontWeight="SemiBold" />
  26. <TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.7"
  27. Text="Set BarLayoutBehavior.Overlay on the page so the nav bar floats above the content. Content scrolls edge-to-edge behind the bar." />
  28. <TextBlock Text="Step 2: Watch scroll offset" FontSize="13" FontWeight="SemiBold" />
  29. <TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.7"
  30. Text="Subscribe to ScrollViewer.OffsetProperty via GetObservable(). Compare each new Y value with the previous to determine direction and magnitude." />
  31. <TextBlock Text="Step 3: Translate the bar" FontSize="13" FontWeight="SemiBold" />
  32. <TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.7"
  33. Text="Apply a TranslateTransform to PART_NavigationBar. Y is clamped between 0 (visible) and –BarHeight (hidden)." />
  34. <TextBlock Text="Step 4: Cleanup" FontSize="13" FontWeight="SemiBold" />
  35. <TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.7"
  36. Text="Dispose the IDisposable returned by GetObservable() when the view is unloaded. Reset TranslateTransform.Y to 0 so the bar is visible when the user returns." />
  37. <Separator />
  38. <TextBlock Text="Thresholds used" FontSize="13" FontWeight="SemiBold" />
  39. <TextBlock FontSize="12" TextWrapping="Wrap" Text="• Hide : scroll down > 8 px" />
  40. <TextBlock FontSize="12" TextWrapping="Wrap" Text="• Show : scroll up > 4 px" />
  41. <TextBlock FontSize="12" TextWrapping="Wrap" Text="• Always show at top (Y ≤ 4)" />
  42. </StackPanel>
  43. </ScrollViewer>
  44. </Border>
  45. </Panel>
  46. </UserControl>