我有一個簡單的ComboBox,每當選定的值更改時,我都要觸發單獨的命令。這裏是我的標記的一個例子:我得到一個錯誤,指出「無法將‘SelectViewFeedDataCommand’」將命令綁定到WPF中的ComboBoxItem
<WrapPanel Grid.Row="0" Visibility="{Binding ShowToggleViewFeedViewManual}">
<ComboBox Margin="3,3,0,0">
<ComboBoxItem IsEnabled="{Binding CanSelectViewFeedData}" >
<ComboBoxItem.CommandBindings>
<CommandBinding Command="SelectViewFeedDataCommand" />
</ComboBoxItem.CommandBindings>
<TextBlock Text="View Feed Data"/>
</ComboBoxItem>
<ComboBoxItem IsEnabled="{Binding CanSelectViewManualData}">
<ComboBoxItem.CommandBindings>
<CommandBinding Command="SelectManualFeedDataCommand" />
</ComboBoxItem.CommandBindings>
<TextBlock Text="View Manual Data"/>
</ComboBoxItem>
</ComboBox>
</WrapPanel>
。我也遇到了另一個ComboBoxItem類似的錯誤。 ICommand在ViewModel類中定義,它是UserControl的DataSource,綁定爲DataTemplate。
public ICommand SelectViewFeedDataCommand
{
get
{
// Code to perform
}
}
我研究這個很廣泛,但還沒有找到如何ICommand的有效結合ComboBoxItem答案。
我正在適應從現有的代碼,使用一組radiobuttons和相關的命令,這是很容易做到這一點。有沒有簡單的方法來使用ComboBox做到這一點?
謝謝。
如何將'ComboBox.SelectedItem'屬性綁定到某個對象,然後在SelectedComboBoxItem屬性的PropertyChanged事件中執行命令邏輯? – Rachel 2012-07-23 18:49:49