What to use instead of StackLayout in a ScrollView?

PantheasPantheas Member ✭✭
edited February 28 in Xamarin.Forms

I have a page with the following structure (simplified):

<ContentPage>
    <ScrollView>
        <StackLayout Orientation="Vertical">
            <Frame>
                <custom:Expander>
                    [actual content here]
                </custom:Expander>
            </Frame>

            <Frame>
                <custom:Expander>
                    [actual content here]
                </custom:Expander>
            </Frame>

            <Frame>
                <custom:Expander>
                    [actual content here]
                </custom:Expander>
            </Frame>

            <Frame>
                <custom:Expander>
                    [actual content here]
                </custom:Expander>
            </Frame>
        </StackLayout>
    </ScrollView>
</ContentPage>

The content of the Frames is not the same.
Imagine yourself the page as some kind of details view for an item.
Every Frame represents a different "section" of associated item information.

I would like to reduce the nesting and replace the ScrollView > StackLayout structure with something more performant.
What are the best practices for scenarios like mine?

Best Answer

  • PantheasPantheas ✭✭
    Accepted Answer

    In case anyone else is coming here wondering which solution I chose:

    I went with the TableView and removed the Frames and Expanders, what also increased the Page's loading speed.

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭
    edited February 28

    I haven't used a TableView myself in a long time but I think it would work here.

  • ColeXColeX Member, Xamarin Team Xamurai

    Have you tried TableView or ListView ?

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    A few options...

    1. Use the new BindableLayout + A Data Template Selector
    2. Use a ListView as the root and a Data Template Selector
    3. Do what you are doing :)

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/

  • PantheasPantheas Member ✭✭
    edited March 1

    Thanks for your suggestions!
    To use either the BindableLayout or the ListView the Model's properties need to be grouped somehow (e.g. in nested classes) and stored in a collection, right?

  • PantheasPantheas Member ✭✭
    Accepted Answer

    In case anyone else is coming here wondering which solution I chose:

    I went with the TableView and removed the Frames and Expanders, what also increased the Page's loading speed.

Sign In or Register to comment.