Mat*_*hew 10 c# xaml pivotitem windows-phone-8
我的页面中有一些透视项目,根据应用程序是否处于试用模式,我需要显示或隐藏其中一个PivotItems.直接在XAML或C#中设置PivotItem的可见性仅隐藏PivotItem内的内容,而不是实际的PivotItem本身.我怎么能做到这一点?
在测试中,我尝试了以下两种方法
Page.xaml
<phone:PivotItem x:Name="PivotItem2" Visibility="Collapsed"
Header="2">
...
</<phone:PivotItem>
Run Code Online (Sandbox Code Playgroud)
要么
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;
}
}
Run Code Online (Sandbox Code Playgroud)
DOT*_*eam 15
您只能使用Pivot.Items集合在Pivot中动态删除或添加PivotItems.你无法隐藏它们.根据您的要求,您可以这样做:
//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"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4043 次 |
| 最近记录: |