如何在WPF(4.5)ComboBoxItem中实现ICommand?我尝试过CommandBinding,但收到错误消息" Command'类型' CommandBinding'的属性。 A'绑定'只能在DependencyObject"
的DependencyProperty上设置答案 0 :(得分:-1)
然后在Windows.xaml中添加以下行。这将添加对XAML的引用
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
你的Combobox XAML就像: -
<ComboBox Name="myComboBox" SelectedValuePath="Content">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding YourCommandName}"
CommandParameter="{Binding ElementName=myComboBox,
Path=SelectedValue}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBoxItem Content="ItemOne" />
<ComboBoxItem Content="ItemTwo" />
<ComboBoxItem Content="ItemThree" />
</ComboBox>