简体   繁体   中英

Collapsable custom viewcell in ListView - Xamarin Forms

This is for Xamarin forms PCL application.

I am looking for solution to have listview which has custom viewcell which show some data on static viewcell and part of it should be collapsible based on button click. the button would be separate than list view, on clicking on it would show or hide some part of viewcell.

Data to show would be dynamic and in parent child relation. Parent data is fixed. Child data contains list of child elements. It can very ie one parent has 2 children and another has 1 or 3. Viewcell should display parent level data on viewcell and on button click it should also show child data in viewcell. 1 row for each child data in viewcell. It is kind of list (parent list) within a list (child list) but child list would be displayed on show button click and should again hide on hide button click.

This viewcell should adjust in height as per its content in hide or show mode ie change in height after it is rendered.

The easiest would be to use a RepeaterView from XLabs inside a ViewCell. Something along the lines of this:

    <ListView ItemsSource="{Binding Parents}">

      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <Grid>
              <Label Text="Fixed Content" />

                <xlabs:RepeaterView x:TypeArguments="local:ChildType" ItemsSource="{Binding Children}">
                  <xlabs:RepeaterView.ItemTemplate>
                    <DataTemplate>
                      <Grid>
                        <Button Text="{Binding ChildAction}">
                        </Button>
                      </Grid>
                    </DataTemplate>
                  </xlabs:RepeaterView.ItemTemplate>
                </xlabs:RepeaterView>

              </Grid>
            </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>

    </ListView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM