WinUI3 Problem with TabView inside ScrollView, it auto scroll the view to its location

23 Views Asked by At

When adding TabView inside a ScrollView, if the TabView is offscreen, it seems to send some signal to the ScrollView to change its scrollview vertical offset position. Even the simple TabView example from WinUI3 Gallery sample acts the same. enter image description here

The expected behavior would be in my humble opinion to leave the ScrollView to Offset position 0 but it seems not the case.

Does anyone know a work around?

1

There are 1 best solutions below

0
Nickyboy On

I finally found out two work around. TabView seemed to be requesting a BringIntoViewRequest.

  1. (At the TabView) If we specify when the request is sent that the request id Handled, then it won't trigger the ChangeView event of the ScrollView.
private void TabView_BringIntoViewRequested(UIElement sender, BringIntoViewRequestedEventArgs args)
{
    args.Handled = true;
}
  1. (At the ScrollView) We can specify to the ScrollView to not trigger BringIntoView when a control receive focus
<ScrollViewer Grid.Row="1" Name="CurrentScrollViewer" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible" 
    ViewChanged="{x:Bind ViewModel.ScrollViewer_OnViewChanged}" HorizontalAlignment="Stretch"
    ViewChanging="CurrentScrollViewer_ViewChanging"                                  
    BringIntoViewOnFocusChange="False"
    >
    <StackPanel x:Name="stackPanel" Margin="0,0,5,0" Spacing="5" MaxWidth="850" />
</ScrollViewer>