你的 Xaml 文件看起来像
<ListBox ItemsSource="{Binding MultipleCopyList, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding HeaderText,Mode=TwoWay}" Grid.Column="1" />
</StackPanel>
</DataTemplate>
</ListBox>
你的触发器看起来像
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<cmd:EventToCommand Command="{Binding DataContext.MouseClickCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter ="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
你的 ViewModel 看起来像
private RelayCommand<StateForm> _MouseClickCommand;
public RelayCommand<StateForm> MouseClickCommand
{
get {
if (_MouseClickCommand == null)
{
_MouseClickCommand = new RelayCommand<StateForm>(e => MouseClick(e));
}
return _MouseClickCommand; }
set
{
_MouseClickCommand = value;
RaisePropertyChanged("MouseClickCommand");
}
}
private void MouseClick(StateForm e)
{
Your Code goes Here
}