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

2

10

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.

Pergolesi answered 7/5, 2016 at 20:25 Comment(0)
S
22

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);
Spurry answered 7/5, 2016 at 22:8 Comment(3)
@hvaughan3- in my case, i want to remove a switch cell from the section dynamically. is there any way?Polyzoarium
@Polyzoarium You should ask a new question and post the question link hereSpurry
You could also check out my solution with bindable sections, which can be changed dynamically from ViewModel: wojciechkulik.pl/xamarin-forms/…Sisson
B
-1
TableSection section = Table.Root.IndexOf(Section);

is wrong because IndexOf returns int

Try

TableSection section = Table.Root[Table.Root.IndexOf(Section)];
Bryology answered 2/9, 2019 at 8:23 Comment(1)
please try to be more descriptive in your explanation and insert the code in code snippetLightweight

© 2022 - 2024 — McMap. All rights reserved.