Application Bar on Subclasses Page

Mar 4, 2012 at 10:25 PM

In the project I am currently working on I have created a BaseView that all the pages inherit from, the BaseView is a PhoneApplicationPage, but obviously all the pages that inherit from this base page are not.

I have added the BindableApplicationBar onto one of the view, but when it runs the following error appears:

System.InvalidOperationException

Bindable.ApplicationBar property needs to be set on a PhoneApplicationPage element.

What is going to be the best way to use the Application Bar in this situation?  Is there any way that I can case the current View to a PhoneApplicationPage to allow the Application Bar to work?

Cheers,
Rupert. 

Coordinator
Mar 6, 2012 at 3:40 AM

Are you setting the Bindable.ApplicationBar property on your derived PhoneApplicationPage or another element inside of it?

Can you share a snippet of your code where you set it?

You can also try using the library as source code so you could debug it yourself.

The code that throws this exception checks if the object you are attaching to is a PhoneApplicationPage, so if BaseView derives from PhoneApplicationPage - it should not throw. The relevant piece of code is here:

var page = d as PhoneApplicationPage;

if (page == null)
{
    throw new InvalidOperationException(
        "Bindable.ApplicationBar property needs to be set on a PhoneApplicationPage element.");
}

Mar 6, 2012 at 4:56 PM

Sorry my fault, I had replaced another bindable app bar with this one, and it was originally contained within a Grid, once I moved it out of the Grid into the Page element it worked OK.

Thanks.