Windows phone wp7处理应用程序栏按钮在枢轴中动态单击
我有一个3页的透视页面,有两个应用程序栏按钮。但我希望当pivot被更改时,应用程序栏的第一个按钮应该在不同的pivot上执行不同的任务,第二个按钮将在所有pivot上执行相同的任务。我这样做是因为: private void PivotControl_SelectionChanged(对象发送方,SelectionChangedEventArgs e) { ApplicationBarIconButton firstButton=(ApplicationBarIconButton)ApplicationBar.Buttons[0]Windows phone wp7处理应用程序栏按钮在枢轴中动态单击,windows-phone,Windows Phone,我有一个3页的透视页面,有两个应用程序栏按钮。但我希望当pivot被更改时,应用程序栏的第一个按钮应该在不同的pivot上执行不同的任务,第二个按钮将在所有pivot上执行相同的任务。我这样做是因为: private void PivotControl_SelectionChanged(对象发送方,SelectionChangedEventArgs e) { ApplicationBarIconButton firstButton=(ApplicationBarIconButton)Applic
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时出现问题。请帮助我使用这个强大的库来简化Windows Phone上ApplicationBar的使用。 你可以在电视上找到它们 还有一个很好的教程,介绍如何使用此库为每个全景/透视项目显示不同的按钮:
使用这个强大的库可以简化Windows Phone上应用程序栏的使用。 你可以在电视上找到它们 还有一个很好的教程,介绍如何使用此库为每个全景/透视项目显示不同的按钮:
以下是我在一个应用程序中如何做到这一点的。按钮1与pivot页面不同,而按钮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事件中,我检测到正在查看的pivot窗格,并使用基本的if…then…else…在同一个处理程序中运行不同的代码。以下是我在一个应用程序中执行此操作的方法。pivot页面的按钮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…在同一个处理程序中运行不同的代码。如果要在运行时动态更改应用程序栏按钮,可以执行以下操作:
<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>
及
您可以使用大量不同的appbar
。
希望得到帮助。如果希望在运行时动态更改应用程序栏按钮,可以执行以下操作:
<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>
及
您可以使用大量不同的appbar
。
希望它能有所帮助