Reputation: 8704
I know that i can hide anything in codebehind, in selectionchanged event handler. But is it possible to, lets say, to have 2 PivotItems and one control outside of pivot, and hide that control, when 1st PivotItem is selected in xaml?
Worked, thanks to @Josh Earl, using the converter:
public class PivotIndexToVisibilityConverter : IValueConverter
{
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
int index = (int)value;
return index == 0 ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
Visibility visibility = ( Visibility )value;
return visibility == Visibility.Visible ? 0 : 1;
}
}
Upvotes: 0
Views: 151
Reputation: 18351
I don't think its possible to do this directly. You could get pretty close, though, if you databound your Visibility
property to the PivotItem.SelectedItem
property. You'd need to create a simple ValueConverter
to translate your PivotItem
index to a Visibility.Collapsed
or Visibility.Visible
as appropriate.
Here's a good intro to ValueConverter
.
Upvotes: 3