Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ApplicationBar is always NULL

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?

like image 321
VansFannel Avatar asked May 09 '11 06:05

VansFannel


1 Answers

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];
like image 137
Nigel Sampson Avatar answered Oct 02 '22 03:10

Nigel Sampson