从父级获取应用程序栏 - Windows Phone
我在 WP7 手机应用程序中使用 MVVM 架构。我当前的视图是一个用户控件,它存在于父页面(标准页面——不是独立的用户控件)内。我已将主页作为父级传递给用户控件的“父级”属性,并且我可以访问父级中的几乎任何控件。例如:这可以访问父级中的可锁定枢轴:
Dim p As LockablePivot
p = MyParent.FindControl("myLockablePivot")
If p IsNot Nothing Then
..do something with the pivot
End If
我的问题是访问父级中的 ApplicationBar 。这是行不通的。我已经三次检查了分配给应用程序栏的 x:Name。 (空引用异常):
Dim ap As ApplicationBar
ap = MyParent.FindName("appBar")
ap.IsVisible = False
任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,但正如 Nigel 在这个答案中指出的那样,
事实证明,有一个 ApplicationBar 属性。您可以使用它访问应用程序栏,然后从那里获取按钮或菜单项。
下面是我在页面构造函数中为本地化文本所做的 C# 示例:
诚然,使用索引来定位项目然后必须进行强制转换是不幸的,但至少它有效!
I hit the same issue, but as Nigel points out in this answer, the
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:
Admittedly, using the index to locate the item and then having to cast is unfortunate, but at least it works!