ApplicationBar is always NULL

北战南征 提交于 2019-12-23 07:03:42

问题


I have the following XAML code:

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="False" x:Name="PageBar">
        <shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.questionmark.rest.png" Text="Help" x:Name="HelpIcon" Click="HelpIcon_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="Help" x:Name="HelpItem" Click="HelpIcon_Click" />
            <shell:ApplicationBarMenuItem Text="About" x:Name="AboutItem" Click="AboutItem_Click" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

But inside C# code is always null.

Do you know why?


回答1:


I found this worked for me when I wanted to change the visiblity:

(ApplicationBar as ApplicationBar).IsVisible = true;

I got that answer from Matthew




回答2:


In some stupid decision an ApplicationBar isn't a standard Silverlight object, because of that it doesn't really fit in the visual tree, can't be bound to and x:Name doesn't work.

You can refer to the ApplicationBar via a property on the PhoneApplicationPage.

var helpItem = this.ApplicationBar.MenuItems[0];
var aboutItem = this.ApplicationBar.MenuItems[1];


来源:https://stackoverflow.com/questions/5933109/applicationbar-is-always-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!