Reputation: 127
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
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
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
Reputation: 942
Use like that
ApplicationBarIconButton myAppIconButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
myAppIconButton .IsEnabled = false;
And you will disable it.
Upvotes: 3