Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide or remove particular tableSection(Xamarin.forms) which created by xaml?

I'm making app with using Xamarin.form.

I created tableview that has three sections from xaml. And I want to hide or remove last section (entire section, with sectionTitle).

But unfortunately, Xamarin xaml doesn't support conditional processing. (only works if element has isVisible property but tableSection does not have it)

Is there any option I can do?

Thanks.

like image 551
Bright Lee Avatar asked May 07 '16 20:05

Bright Lee


1 Answers

Yes you can remove a section dynamically doing the following:

XAML:

<TableView x:Name="Table">
    <TableSection x:Name="Section">
        <TextCell Text="something"/>
    </TableSection>
    <TableSection x:Name="Section2">
        <TextCell Text="something2"/>
    </TableSection>
</TableView>

Code Behind:

Table.Root.Remove(Section);

-OR-

Table.Root.Remove(0); //If you know the index of the section

If you need to add it back at some point, be sure to store it in a variable in you code behind before removing it like so:

TableSection section = Table.Root[0];

-OR-

TableSection section = Table.Root.IndexOf(Section);
like image 168
hvaughan3 Avatar answered Nov 07 '22 07:11

hvaughan3