I have been working in Xamarin Forms lately for a project, and I have been using the TableView to show details of a record retrieved from web api. Sometimes, certain details are not present, so I'd like to hide the section that displays the information.
However, I can't find a way to hide the TableSection.
Here's some XAML:
<TableView>
<TableRoot>
...
<!--Contact info-->
<TableSection IsVisible="{Binding HasContact}" Title="Contact">
<!--Contact name-->
<TextCell Text="{Binding ContactName}" Detail="Primary contact" />
<!--Phone-->
<TextCell Text="Phone"
Detail="{Binding FormattedContactPhoneNumber}"
Command="{Binding BindingContext.DialPhoneCommand, Source={x:Reference MainGrid}}"
CommandParameter="{Binding ContactPhoneNumber}"/>
<!--Email-->
<TextCell Text="Email"
Detail="{Binding ContactEmail}"
Command="{Binding BindingContext.SendEmailCommand, Source={x:Reference MainGrid}}"
CommandParameter="{Binding ContactEmail}"/>
</TableSection>
</TableRoot>
</TableView>
Obviously, the IsVisible property didn't work and throws an exception because it doesn't exist (It is present on other elements like Labels). I also tried using VisualElement.IsVisible
which throws an invalid cast exception. So is there any way to hide this section?
If there isn't a way to do it, perhaps I'll need to go down a dirtier path and use separate TableViews (There I can use VisualElement.IsVisible) :(
Visibility
property you would put your bool through a converter for to be eitherVisible
orCollapsed
as the param. ie;Visibility="Collapsed"
– Chris W.