Can I hide (not delete) PivotItem?

I have a situation where I show a set of PivotItem and (depending on the situation) selected.

I need to hide this bar when the List containing my favorites is empty - but it should appear when there is something there.

Now I could just delete it, but what about this scenario:

  • Go to the summary view (no favorite-turn, as the list is empty)
  • Scroll to one of the remaining PivotItem and select an item.
  • Select this item as a favorite in your own view.
  • Click the back button and return to the summary view.

Now there will be no favorites β€” a twist, and that's just not enough.

I tried to remove it with Visibility = "hidden", but VS complains that the data context is not set correctly (it is.)

Any ideas?

+6
source share
2 answers

Why not add and remove PivotItem dynamically in your code in response to user events? User adds favorites -> creates and adds a Pivot element. The user deletes his last favorite element -> removes the Pivot element.

+3
source

I assume that you would have a favorites list in this pivot element, so my approach would be to bind the visibility of the pivot table item to the isEmpty property of the list.

For example, the view will be

 <PivotItem Visibility="{Binding IsNotEmpty, Converter={StaticResource VisibilityConverter}}"/> 

and in viewmodel

 ICollectionView ItemsSource; ... public bool IsNotEmpty(){ return !ItemsSource.IsEmpty; } 

and finally the converter

 public class BooleanToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value == null) return Visibility.Collapsed; var isVisible = (bool)value; return isVisible ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var visiblity = (Visibility)value; return visiblity == Visibility.Visible; }} 

Converter derived from Useful Converters

0
source

Source: https://habr.com/ru/post/921191/


All Articles