您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>
和您的视图模型样子
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
}
你应该能够只通过目标ct本身作为'CommandParameter'使用'CommandParameter =“{绑定}” – Rachel
thnx去试试吧;) 它的工作!你是伟大的:D –
重要的是你明白为什么工作......理解绑定, 该特定行的DataContext是一个人所以{绑定}是{Binding Path = DataContext}的简称} –