View层:
xmlns:i=http://schemas.microsoft.com/expression/2010/interactivity
<ComboBox x:Name="comboBox1" Height="23" Width="120" SelectedValuePath="StuId" DisplayMemberPath="StuName" ItemsSource="{Binding StudentList}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectItemChangedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
ViewModel层:
public ICommand SelectItemChangedCommand { get; set; }
构造函数中
SelectItemChangedCommand = new ActionCommand(this.NotifySelectedItemChanged);
事件7a686964616fe78988e69d8331333332613730:
public void NotifySelectedItemChanged()
{
MessageBox.Show("Sucess");
}

本文介绍在WPF应用中如何使用MVVM模式实现ComboBox与Viewmodel之间的数据绑定及事件触发。通过设置ComboBox的SelectedValuePath、DisplayMemberPath属性与Viewmodel中的数据源绑定,并利用自定义的SelectItemChangedCommand处理SelectionChanged事件。
8487

被折叠的 条评论
为什么被折叠?



