Vali Maties
Vali Maties

Reputation: 164

MAUI BringIntoView() the ContentView like in WPF

For a control in WPF there is a BringIntoView() function which automatically will scroll the parent to be able to see the entire control. Is there something simmilar for a ContentView in MAUI?

Edit:

Based on comment of @FreakyAli , if there is not such an event, how could this be done? How can I automatically scroll the ScrollView which contains an ExtendedFlexLayout control, with a custom view set as CollectionView.ItemTemplate? My ScrollView looks like this:

<ScrollView VerticalScrollBarVisibility="Default" >
    <controls:ExtendedFlexLayout
        AlignItems="Start"
        Direction="Row"
        Wrap="Wrap"
        ItemsSource="{Binding PacksList}">
        <controls:ExtendedFlexLayout.ItemTemplate>
            <DataTemplate>
                <views:PackView />
            </DataTemplate>
        </controls:ExtendedFlexLayout.ItemTemplate>
    </controls:ExtendedFlexLayout>
</ScrollView>

ExtendedFlexLayout is a custom FlexLayout control.

Upvotes: 0

Views: 316

Answers (1)

Vali Maties
Vali Maties

Reputation: 164

Based on @ewerspej comment, I found that ScrollToAsync() event has two constructors. Both constructor accept three arguments, the third one is for animating scroll process for both constructors.

The first constructor allows you to Scroll a position into view and it passes two values of double type, one for the x (horizontal) and one for the y (vertical).

await scrollView.ScrollToAsync(0, 150, true);

The second constructor is for Scroll an element into view, which accept a visual element as the first argument, the second argument is ScrollToPosition enum, which offers four options: MakeVisible, Start, Center and End.

The following example will bring into view the label, and will align it to the bottom of scrollView control:

await scrollView.ScrollToAsync(label, ScrollToPosition.End, true);

The link to Microsoft MAUI ScrollView page is HERE .

Upvotes: 0

Related Questions