Reputation: 205
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.
Upvotes: 2
Views: 206
Reputation: 729
You can't access AppBarButtons that way.
Try
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Click -= new System.EventHandler(Customization);
Upvotes: 2