xaml:
添加引用xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
添加控件
<ListBox Width="180" HorizontalAlignment="Left"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Products}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedProducts}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding AddProductCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
C# :
添加命令
private RelayCommand _addProductCommand;
public ICommand AddProducCommand
{
get
{
if (this._addProductCommand == null)
{
this._addProductCommand = new RelayCommand(
() => this.AddSelectedProduct(),
() => true);
}
return this._addProductCommand;
}
}
public AddSelectedProduct()
{
.....
}