C# 如何在Caliburn.Micro中获得下拉选择的CanXXX行为?

C# 如何在Caliburn.Micro中获得下拉选择的CanXXX行为?,c#,caliburn.micro,C#,Caliburn.micro,如果我有一个名为Execute的按钮,我可以编写一个方法来控制该按钮的可点击性: public bool CanExecute() { return !string.IsNullOrWhiteSpace(this.SelectedCatalogName) && !string.IsNullOrWhiteSpace(this.selectedCommandName); } 类似地,我有一个名为SelectedCommand的下拉列表,在选择另一个下拉列表之前,应该禁用该下

如果我有一个名为Execute的按钮,我可以编写一个方法来控制该按钮的可点击性:

public bool CanExecute()
{
    return !string.IsNullOrWhiteSpace(this.SelectedCatalogName) && !string.IsNullOrWhiteSpace(this.selectedCommandName);
}
类似地,我有一个名为SelectedCommand的下拉列表,在选择另一个下拉列表之前,应该禁用该下拉列表:

private BindableCollection<string> catalogNames;
public BindableCollection<string> CatalogNames
{
    get
    {
        return this.catalogNames;
    }
}

private string selectedCatalog;
public string SelectedCatalogName
{
    get
    {
        return this.selectedCatalog;
    }
    set
    {
        this.selectedCatalog = value;
        this.NotifyOfPropertyChange(() => this.SelectedCatalogName);
    }
}
// -----------------------------------------------------------------
// --> Can I do this or the equivalent?
// -----------------------------------------------------------------
public bool CanSelectCatalogName()
{
    return !string.IsNullOrWhiteSpace(this.SelectedCatalogName);
}
私有BindableCollection目录名;
公共BindableCollection目录名
{
得到
{
返回此目录名;
}
}
私有字符串选择目录;
公共字符串SelectedCatalogName
{
得到
{
返回此.selectedCatalog;
}
设置
{
this.selectedCatalog=值;
this.NotifyOfPropertyChange(()=>this.SelectedCatalogName);
}
}
// -----------------------------------------------------------------
//-->我可以执行此操作或等效操作吗?
// -----------------------------------------------------------------
公共bool可以选择CatalogName()
{
return!string.IsNullOrWhiteSpace(this.SelectedCatalogName);
}

注意:以上评论中有问题。

没有内置的约定来支持这一点,但您只需执行一个简单的绑定:

<ComboBox x:Name="SelectedCatalog" IsEnabled="{Binding CanSelectCatalogName}" />


谢谢,但现在我有点困惑,为什么按钮的约定会存在,如果这就是它所需要的(我相信这是有原因的,我只是还不明白),我怀疑是因为Caliburn Micro正在取代处理Execute()/CanExecute()模式的ICommand功能。