2012-03-09 24 views
2

如果我有一個名爲按鈕執行,我可以寫一個方法來控制按鈕的可點擊:如何在Caliburn.Micro中爲下拉選擇獲取CanXXX行爲?

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); 
} 

注意:上面評論中的問題。

回答

2

沒有支持這個內置的約定,但你可以做一個簡單的綁定:

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

感謝,但現在我爲何buttons的約定存在,如果這一切都需要稍微困惑(我確定有一個原因,我只是沒有看到它) – 2012-03-09 16:53:48

+0

我懷疑是因爲Caliburn Micro取代了ICommand功能,它處理了Execute()/ CanExecute()模式。 – 2012-03-10 01:03:52

相關問題