开发者

Can't access the Application buttons from c# (Windows Phone 7)

I'm writing a Windows Phone 7 app and want to programmtically access my Application bar buttons when the page loads. But these always appear to be null. I've tried accessing the button in the following events:

  • Page Contructor (after call to InitializeComponent)
  • Page's `Loaded' event handler
  • The Application Bars StateChanged event 开发者_如何转开发handler

There don't appear to be a Loaded event on the individual buttons either. Am I breaking the rules here? Why can't I access the application bar buttons with c#?


When I looked at this in one the CTPs, it was possible to access elements as I outlined in this thread.

Cannot change ApplicationBar items in code

Note that access to Application Bar elements is available through the type rather than the instance as you might initially expect.

Peter Torr clarified soon after that the Application Bar isn't quite a first class citizen in the framework. Explained here in more detail for your reference.

Why are the ApplicationBar objects not FrameworkElements? - Peter Torr's Blog


To localize the button text, in the page's Loaded event handler, I've been iterating over the page's ApplicationBar.Buttons list and replacing the value in the button's Text property with the resource translation. Seems to work, even if it's kludgy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜