Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Hide Visibility of Individual PivotItem

I have a few pivot items in my page, and based upon whether the app is in trial mode or not I need to show or hide one of the PivotItems. Setting the Visibility of the PivotItem directly in XAML or in C# only hides what is within the PivotItem, not the actual PivotItem itself. How can I accomplish this?

In testing I've tried both of the following

Page.xaml

<phone:PivotItem x:Name="PivotItem2" Visibility="Collapsed"
                         Header="2">
                ...
</<phone:PivotItem>

OR

Page.xaml.cs

 protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        //Check trial state and set PivotItem
        if ((Application.Current as App).IsTrial)
        {
            PivotItem2.Visibility = Visibility.Collapsed;
        }
        else
        {
            PivotItem2.Visibility = Visibility.Visible;
        }
    }
like image 675
Matthew Avatar asked Nov 13 '14 12:11

Matthew


People also ask

How to hide pivot items in pivot?

You can only remove or add PivotItems dynamically in your Pivot using Pivot.Items collection. You can not hide them. As per your requirement, you can do this :

Is it possible to hide the pivotitem in the visualtree?

This was always possible in other controls like in WPF's TabControl which Pivot was supposed to replace. However, in UWP, setting PivotItem.Visiblity=Collapsed will hide the Content but the PivotItem and its header are still shown within the Pivot and appear in the VisualTree.

What is the visible property for a PivotTable item?

expression A variable that represents a PivotItem object. The Visible property for a PivotTable item is True if the item is currently visible in the table. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

How to remove pivot items from a page?

Maybe you can do it such a way: Prepare the whole pivot, in Page's constructor check if trial mode - if yes - remove the pivotitem. You can only remove or add PivotItems dynamically in your Pivot using Pivot.Items collection. You can not hide them.


1 Answers

You can only remove or add PivotItems dynamically in your Pivot using Pivot.Items collection. You can not hide them. As per your requirement, you can do this :

//Check trial state and set PivotItem
if ((Application.Current as App).IsTrial)
{
    PivotControl.Items.Remove(PivotControl.Items.Single(p => ((PivotItem)p).Name == "Name_PivotItem"));
}
else
{
    PivotControl.Items.Add(PivotControl.Items.Single(p => ((PivotItem)p).Name == "Name_PivotItem"));
}
like image 138
DOTNET Team - WeblineIndia Avatar answered Oct 20 '22 17:10

DOTNET Team - WeblineIndia