Reputation: 86075
I want to gray out a button dynamically. How to do that?
Upvotes: 3
Views: 5446
Reputation: 7351
here id more sophisticated way (WPF way) is to bind Command to the Button.
<Button Name="button1" VerticalAlignment="Top" Width="94" Command="{Binding MyCommand}"
in ViewModel which is bound to the view's dataContext:
public ICommand MyCommand
{
get
{
return new DelegateCommand<string>(ExecuteSomething,IsExecutable);
}
}
here is ExecuteSomething the method which will be executed by clicking your button IsExecutable - perdicate while it returns false the Button will be disable
Upvotes: 0
Reputation: 7709
in xaml
<Button Name="myButton">Click Me</Button>
in code behind
myButton.IsEnabled = false;
Upvotes: 11