1

I'm using MVVM architecture in a WP7 phone app. My current view is a user control, which exists inside of a parent page (standard page -- not stand-alone user control). I have passed the main page as a parent to a "parent" property of the user control, and I can access pretty much any control in the parent. For example: this works to access a lockable pivot in the parent:

Dim p As LockablePivot
p = MyParent.FindControl("myLockablePivot")
If p IsNot Nothing Then
..do something with the pivot
End If

My problem is in accessing the ApplicationBar in the parent. This does not work. I have triple checked the x:Name assigned to the application bar. (null reference exception):

    Dim ap As ApplicationBar
    ap = MyParent.FindName("appBar")

    ap.IsVisible = False

Any help would be appreciated.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
Matthew Pitts
  • 809
  • 1
  • 8
  • 13

1 Answers1

3

I hit the same issue, but as Nigel points out in this answer, the

"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."

It turns out that there is an ApplicationBar property on the PhoneApplicationPage class. You can use it to access the Application Bar and then grab the Buttons or MenuItems from there.

Here is a C# example of what I did in my page constructor to localize the text:

public MyPage()
{
    InitializeComponent();

    (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).Text = AppResources.event_add_menu_item;
}

Admittedly, using the index to locate the item and then having to cast is unfortunate, but at least it works!

Community
  • 1
  • 1