0
votes

I'm learning to develop applications in Windows Phone (for Mango). While using an appbar in a Panorama page, i wish to change the menu items and button text etc. according to the page selected (like the Music+Videos app).

For this, i created the application bar in xaml as:

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar x:Name="appbar" IsMenuEnabled="True" IsVisible="True">
            <shell:ApplicationBarIconButton Text="Add" IconUri="/add.png" x:Name="btn" Click="Addbtn"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="Exit" x:Name="menuitem" Click="menubtn"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

Then, i tried manipulating the controls by trying to access the appbar by its x:name property in the SelectionChanged event of the panorama page as:

    private void PanoControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            if (PanoControl.SelectedIndex == 0)
                appbar.IsMenuEnabled = false;
            else if(PanoControl.SelectedIndex == 1)
                menuitem.IsEnabled = false;
            else if (PanoControl.SelectedIndex == 2)
            {
                appbar.IsVisible = true;
                menuitem.IsEnabled = true;
            }
        }

When moving from one panorama page to other, an exception is generated. Please help me out. Is this even possible?

Also, i'm asking a question here for the first time. Please let me know if i missed out on something.

Thanks, Siddhant

2
You could tell us what is the exception..prthrokz

2 Answers

2
votes

Access the app bar items through the ApplicationBar property of the page. It makes manipulations cumbersome.

private void PanoControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

    if (PanoControl.SelectedIndex == 0)
        this.ApplicationBar.IsVisible = false;
    else if(PanoControl.SelectedIndex == 1)
        ((ApplicationBarMenuItem)ApplicationBar.MenuItems[0]).IsEnabled = false;
    else if (PanoControl.SelectedIndex == 2)
    {
        this.ApplicationBar.IsVisible = false;
        ((ApplicationBarMenuItem)ApplicationBar.MenuItems[0]).IsEnabled = false;
    }
}

The community has developed some solutions. One is BindableApplicationBar, I'm not sure if its for Mango or Windows Phone 8. This project is Mango-specific http://phone7.codeplex.com/

1
votes

Because the ApplicationBar is a shell object, you can't reference it with a name like any other XAML object. It is associated with your page, so you can use this.ApplicationBar:

this.ApplicationBar.IsVisible = false;