将ComboBox的Selectchanged事件binding到ViewModel
通过Nuget安装 System.Windows.Interactivity.WPF
- 使用System.Windows.Interactivity.dll,添加该dll到项目引用
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
XAML代码如下:
<ComboBox x:Name="cb_categoryCombin" Margin="3" SelectedIndex="0" HorizontalContentAlignment="Center" MinWidth="190"
ItemsSource="{Binding CategoryCombinList}" DisplayMemberPath="Name" SelectedValuePath="Content" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CategoryCombin_SelectionChangedCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<ComboBox x:Name="cb_categoryCombin" Margin="3" SelectedIndex="0" HorizontalContentAlignment="Center" MinWidth="190"
ItemsSource="{Binding CategoryCombinList}" DisplayMemberPath="Name" SelectedValuePath="Content" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding DetailVM.CategoryCombin_SelectionChangedCommand}"
CommandParameter="{Binding ElementName=cb_categoryCombin,Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>