私は、選択した値が変更されるたびに別々のコマンドをトリガーする単純なComboBoxを持っています。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>
私は「は 『SelectViewFeedDataCommand』を変換できません」というエラーが出ます:ここに私のマークアップの例があります。他のComboBoxItemについても同様のエラーが発生します。 ICommandは、UserControlのDataSourceであるViewModelクラスで定義され、DataTemplateとしてバインドされています。
public ICommand SelectViewFeedDataCommand
{
get
{
// Code to perform
}
}
私はかなり広範囲にこれを研究してきたが、効果的にComboBoxItemへのICommandをバインドする方法については答えを見つけることができます。
これは、ラジオボタンと関連コマンドのセットを使用していた既存のコードからこれを適用しています。これは非常に簡単です。 ComboBoxでこれを行う簡単な方法はありませんか?
ありがとうございました。
「ComboBox.SelectedItem」プロパティを何かにバインドして、SelectedComboBoxItemプロパティの「PropertyChanged」イベントでコマンドロジックを実行するとどうなりますか? – Rachel