我正在尝试根据用户输入的数据启用和禁用 WPF (PRISM) 用户控件中的按钮。
In the constructor I do
SubmitCommand = new DelegateCommand<object>(OnSubmit, CanSubmit);
public ICommand SubmitCommand { get; private set; }
private void OnSubmit(object arg)
{
_logger.Log(arg.ToString());
}
private bool CanSubmit(object arg)
{
return Title.Length > 0;
}
private string _title="";
public string Title
{
get { return _title; }
set
{
if (_title != value)
{
_title = value;
this.RaisePropertyChanged();
}
}
}
我在 Xaml 中绑定了 SubmitCommand,如下所示
<Button Content="Submit" Width="100" Command="{Binding Path=SubmitCommand}" CommandParameter="{Binding ElementName=TitleText, Path=Text}" />
问题是当标题值更改时,按钮没有启用。可能是我错过了一些东西。谢谢你的帮助!