user3008134
user3008134

Reputation: 127

Disabling ApplicationBarIconButton in wp7

I've two applicationbariconbuttons, out of which one is to be enabled only if certain conditions are met. My Code in C#

if (//conditions)
  {
     ((ApplicationBarIconButton)DeleteButton).IsEnabled = false;
  }

But while excecution, i get the following error,

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll

Help me to solve this one.

Thanks in advance

Upvotes: 0

Views: 267

Answers (3)

Aju
Aju

Reputation: 806

Eventhough we can keep name for the application bar icon button, we can not disable or enable it using the name given in x:Name="". So use the follwoing code,

((ApplicationBarIconButton)ApplicationBar.Buttons[index]).IsEnabled = true;

Upvotes: 1

A.K.
A.K.

Reputation: 3331

Application bar buttons are stored in a list you would have to call it by referring to a particular item like this.

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false;

This would solve the purpose.

Upvotes: 1

Nikhil Prajapati
Nikhil Prajapati

Reputation: 942

Use like that

 ApplicationBarIconButton myAppIconButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];

 myAppIconButton .IsEnabled = false;

And you will disable it.

Upvotes: 3

Related Questions