2010-12-21 89 views

回答

10
在XAML

<Button Name="myButton">Click Me</Button> 
代码

背后

myButton.IsEnabled = false; 
1

将其IsEnabled属性设置为false。您可以在代码隐藏或触发器/样式中执行此操作,具体取决于您在那里的需求。

0

这里ID更复杂的方式(WPF方式)是命令绑定到按钮。

<Button Name="button1" VerticalAlignment="Top" Width="94" Command="{Binding MyCommand}" 
在视图模型

这势必视图的DataContext的:

public ICommand MyCommand 
    { 
     get 
     { 
      return new DelegateCommand<string>(ExecuteSomething,IsExecutable); 
     } 
    } 

这里ExecuteSomething将通过点击按钮 IsExecutable执行的方法 - perdicate同时返回false按钮将被禁用