2

Why would I do that, anyway? Here it is: My application bar item respond to click like this:

 <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Click="Customization" x:Name="Custom"

It allows the user to go to settings page, but the user still has something to do before the app navigates. The actual event that will make the app navigates is triggered by a normal button. So, before, the user do that, I'd like to remove the event suscriber from the application bar item. If I try this in the beginning of method "Customization":

 Custom.Click -= new System.EventHandler(Customization);

I got NullReferenceException.

That's how I do for my "normal" items and it works. This is the first time I'm using a System.EventHandler, so there's probably something that I'm missing.

Later in the scenario, I'd like to be able to re-add this suscriber to the application bar item. Any help appreciated, thank you.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eric Philippe
  • 195
  • 1
  • 1
  • 9

1 Answers1

2

You can't access AppBarButtons that way.

Try

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Click -= new System.EventHandler(Customization);
simple-thomas
  • 671
  • 7
  • 20
  • HI, Thank you for your answer, but VS reports two errors: type or namespace 'ApplicationBarIconButton'could not be found; and 'object' does not contain a definition for 'Click' and no extension method 'Click'accepting a first argument of type 'object' could be found. Would you know why? Thannks again – Eric Philippe Feb 28 '13 at 17:41
  • Right click ApplicationBarIconButton and select Resolve and import the using if there are any. I don't know why it would give an error other than that. – simple-thomas Feb 28 '13 at 17:48
  • Good, thank you! It removed one error but VS still report that'object'does not contain a definition for 'Click'and no extension method 'Click' blah blah blah, which is quite strange since I used the word Click in my Xaml ??...Thank you for your time and your tip, i will certainly use it in the future... – Eric Philippe Feb 28 '13 at 18:20
  • Check my answer again, I fixed it. I needed the parentesis. Mark me as the answer please – simple-thomas Feb 28 '13 at 18:26
  • It's a joy to mark you as answer, it works perfectly and I would never have found that by myself. Thanks A LOT!!!!! Whish you the best – Eric Philippe Feb 28 '13 at 18:38