Button.IsEnabled
不能正常工作。
我已经调试了代码,该属性的设置器被“ true”值击中。但是该按钮仍处于禁用状态。
View.xaml:
<StackPanel Grid.Row="2" Margin="0,20,0,0" >
<Button Name="ButtonOk" Content="OK" Margin="0,0,4,0" IsEnabled="{Binding SomethingIsValid}" Command="{Binding CommandOk}" />
<Button Name="ButtonCancel" Content="Cancel" Margin="0,0,4,0" IsCancel="True" /
</StackPanel>
View.xaml.cs:
...
public View(ViewModel viewModel)
{
this.InitializeComponent();
this.viewModel = viewModel;
this.DataContext = viewModel;
}
ViewModel:
public bool SomethingIsValid
{
get
{
return somethingIsValid;
}
set
{
this.somethingIsValid= value;
this.RaisePropertyChanged(() => this.SomethingIsValid);
}
}
#region IDataErrorInfo
public string this[string columnName]
{
get
{
this.SomethingIsValid= false;
if ("SomeName" == columnName)
{
if (string.IsNullOrEmpty(this.Status))
{
return "Please bla bla..";
}
}
this.SomethingIsValid = true;
return string.Empty;
}
}
public string Error
{
get
{
return string.Empty;
}
}
#endregion
public ICommand CommandOk
{
get
{
if (this.commandOk == null)
{
this.commandOk = new RelayCommand(this.CommandOkAktion, () => this.SomethingIsValid );
}
return this.commandOk;
}
}
如果您使用的是命令,则单独绑定按钮的IsEnabled属性不是一个好主意。而是应在命令的“ CanExecute”中提供正确的值。这也将启用该按钮。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句