我使用带有变量 appbar 的枢轴控件。如我所见,appbar 链接到 app.xaml.cs 中的资源,您可以在其中放置按钮及其方法的信息。它看起来像这样:
<shell:ApplicationBar x:Key="AppBar1" IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.places.png" Text="TEXT" Click="ApplicationBarIconButton_Click11" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.calendar.month.png" Text="TEXT" Click="ApplicationBarIconButton_Click12" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.star.png" Text="TEXT" Click="ApplicationBarIconButton_Click13" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.people.multiple.png" Text="TEXT" Click="ApplicationBarIconButton_Click14" />
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="AppBar2" IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.warning.circle.png" Text="TEXT" Click="ApplicationBarIconButton_Click21" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.qr.png" Text="TEXT" Click="ApplicationBarIconButton_Click22" />
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="AppBar3" IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.add.png" Text="TEXT" Click="ApplicationBarIconButton_Click31" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.message.png" Text="TEXT" Click="ApplicationBarIconButton_Click32" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.email.png" Text="TEXT" Click="ApplicationBarIconButton_Click33" />
<shell:ApplicationBarIconButton IconUri="/Images/iconos/appbar.warning.circle.png" Text="TEXT" Click="ApplicationBarIconButton_Click34" />
</shell:ApplicationBar>
每个不同的按钮都有一个方法,实际上导航到另一个部分的按钮工作正常:
private void ApplicationBarIconButton_Click11(object sender, EventArgs e)
{
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/seccmapa/localeslist.xaml", UriKind.Relative));
}
但是现在我想要其中一个按钮在主页中调用一个方法,我尝试了这样的事情:
private void ApplicationBarIconButton_Click51(object sender, EventArgs e)
{
((MainPage)App.Current.RootVisual).cambioperfil();
}
MainPage 中的方法是:
public async void cambioperfil()
{
objetoslistas.setprofileinput paquete = new objetoslistas.setprofileinput();
paquete.nickName = nombre.Text;
paquete.statusMessage = status.Text;
paquete.isMen = isMen;
paquete.birthDate = Fecha_nacimiento.Value.ToString();
if (Visibilidad.IsChecked == true)
{
paquete.mapVisibility = true;
}
else
{
paquete.mapVisibility = false;
}
Uri url = new Uri("url");
string respuesta = await metodosJson.jsonPOST(url, paquete);
}
但这给出了 mi 和异常:
{System.InvalidCastException: Unable to cast object of type 'Microsoft.Phone.Controls.PhoneApplicationFrame' to type 'X.MainPage'
任何想法?