1

我有一个包含 3 页的数据透视页面,并且有两个应用程序栏按钮。但我希望当枢轴改变时,应用程序栏的第一个按钮应该在不同的枢轴上执行不同的任务,第二个按钮将在所有枢轴上执行相同的任务。我这样做是:

private void PivotControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { ApplicationBarIconButton firstButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];

        if (PivotControl.SelectedIndex == 0)
        {               
            firstButton.IsEnabled = true;
            firstButton.Click += new EventHandler(FirstPivotButton_Click);
        }
        else if (PivotControl.SelectedIndex == 1)
        {
            firstButton.IsEnabled = true;
            firstButton.Click += new EventHandler(SecondPivotButton_Click);

        }
        else if (PivotControl.SelectedIndex == 2)
        {
            firstButton.IsEnabled = false;                
        }
  }

    void FirstPivotButton_Click(object sender, EventArgs e)
    {
        NavigationService.Navigate(new Uri("/PageA.xaml", UriKind.Relative));
    }

    void SecondPivotButton_Click(object sender, EventArgs e)
    {
        NavigationService.Navigate(new Uri("/PageB.xaml", UriKind.Relative));
    }

但问题是 PageA 的导航很好,但是从 secondpivotbutton 单击事件转到 PageB 时存在问题。请帮我

4

3 回答 3

1

使用这个出色的库来简化 Windows Phone 上 ApplicationBar 的使用 - AppBarUtils您也可以在NuGet上找到它们。

还有很好的教程,如何使用这个库为每个全景图/透视项目显示不同的按钮:http:
//allenlooplee.wordpress.com/2012/09/17/how-to-show-different-app-bar-for -不同的pivotpano项目/

于 2013-04-13T11:03:41.640 回答
0

这是我在我的一个应用程序中执行此操作的方法。按钮 1 与数据透视页面不同,按钮 2 始终相同,就像您一样。

在 SelectionChanged 事件上,更新按钮图标 uri 和文本:

Private Sub statPivot_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles statPivot.SelectionChanged
        Dim saveBtn As ApplicationBarIconButton = ApplicationBar.Buttons(0)

        If statPivot.SelectedIndex = 0 Then
            'calculation pane active
            saveBtn.Text = "save"
            saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.save.rest.png", UriKind.Relative)
        Else
            'history pane active
            saveBtn.Text = "clear"
            saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.refresh.rest.png", UriKind.Relative)
        End If
    End Sub

然后在 onclick 事件中,我检测到正在查看的数据透视窗格并使用基本的 if...then...else... 在同一处理程序中运行不同的代码。

于 2013-04-13T22:13:26.873 回答
0

如果您想在运行时动态更改应用栏按钮,您可以这样做:

 <phone:PhoneApplicationPage.Resources>
    <shell:ApplicationBar x:Key="appbar1" IsVisible="True">
        <shell:ApplicationBarIconButton x:Name="abMain1" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla1"/>
    </shell:ApplicationBar>

    <shell:ApplicationBar x:Key="appbar2" IsVisible="True">
        <shell:ApplicationBarIconButton x:Name="abMain2" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla2"/>
        <shell:ApplicationBarIconButton x:Name="abMain3" IconUri="/icons/appbar.cancel.rest.png" Text="blabla3"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>

然后从代码中更改它:

 ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar1"];

 ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar2"];

您可以使用大量不同的AppBars. 希望它的帮助。

于 2013-04-15T06:17:12.040 回答