更改应用程序栏可见性时应用程序崩溃
Application crashes on changing Application Bar visibility
我正在创建一个全景应用程序,我想自定义一个应用程序栏,这样它就只会在一个页面上可见。
我在 XAML:
中创建了应用程序栏
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar x:Name="AppBar_Opere" IsVisible="False" IsMenuEnabled="True" Mode="Default" Opacity="0.95" >
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar/feature.search.png" Text="cauta" />
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar1/favs.png" Text="favorite" />
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar2/feature.settings.png" Text="setari" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Clasa a IX-a" />
<shell:ApplicationBarMenuItem Text="Clasa a X-ea" />
<shell:ApplicationBarMenuItem Text="Clasa a XI-ea" />
<shell:ApplicationBarMenuItem Text="Clasa a XII-ea" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
然后,使用 SelectionChanged 事件,我编写了这段代码:
private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch(((Panorama)sender).SelectedIndex)
{
case 1:
AppBar_Opere.IsVisible = true;
break;
default:
AppBar_Opere.IsVisible = false;
break;
}
}
好的。当我导航到我希望 ApplicationBar 可见的页面时,应用程序崩溃,并显示“对象引用未设置为对象的实例”
在线:
AppBar_Opere.IsVisible = true;
为什么?
ApplicationBar 不是 silverlight 控件,所以您不能那样访问它。
正确代码是:
private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch(((Panorama)sender).SelectedIndex)
{
case 1:
ApplicationBar.IsVisible = true;
break;
default:
ApplicationBar.IsVisible = false;
break;
}
}
我正在创建一个全景应用程序,我想自定义一个应用程序栏,这样它就只会在一个页面上可见。 我在 XAML:
中创建了应用程序栏<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar x:Name="AppBar_Opere" IsVisible="False" IsMenuEnabled="True" Mode="Default" Opacity="0.95" >
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar/feature.search.png" Text="cauta" />
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar1/favs.png" Text="favorite" />
<shell:ApplicationBarIconButton IconUri="/Assets/AppBar2/feature.settings.png" Text="setari" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Clasa a IX-a" />
<shell:ApplicationBarMenuItem Text="Clasa a X-ea" />
<shell:ApplicationBarMenuItem Text="Clasa a XI-ea" />
<shell:ApplicationBarMenuItem Text="Clasa a XII-ea" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
然后,使用 SelectionChanged 事件,我编写了这段代码:
private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch(((Panorama)sender).SelectedIndex)
{
case 1:
AppBar_Opere.IsVisible = true;
break;
default:
AppBar_Opere.IsVisible = false;
break;
}
}
好的。当我导航到我希望 ApplicationBar 可见的页面时,应用程序崩溃,并显示“对象引用未设置为对象的实例” 在线:
AppBar_Opere.IsVisible = true;
为什么?
ApplicationBar 不是 silverlight 控件,所以您不能那样访问它。 正确代码是:
private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch(((Panorama)sender).SelectedIndex)
{
case 1:
ApplicationBar.IsVisible = true;
break;
default:
ApplicationBar.IsVisible = false;
break;
}
}