WPf 如何将combox的selectionchanged事件和command绑定?
1个回答
展开全部
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);
事件:
public void NotifySelectedItemChanged()
{
MessageBox.Show("Sucess");
}
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);
事件:
public void NotifySelectedItemChanged()
{
MessageBox.Show("Sucess");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询