ItemTemplate中带按钮的ListBox:按钮上的单击选中FireChanged

时间:2010-10-27 15:35:59

标签: silverlight

我在ItemTemplate中有一个带Button的ListBox。当我按下按钮时,一些命令被触发。我希望ListBox在Button Click事件发生时触发SelectionChanged事件。我如何解雇ListBox SelectionChanged事件并传递适当的上下文?

<ListBox ItemsSource="{Binding SomeSource}" >
 <ListBox.ItemTemplate>
 <DataTemplate>
  <Button Grid.Row="0" BorderThickness="0" Background="Transparent" HorizontalAlignment="Stretch">
  <i:Interaction.Triggers>
   <i:EventTrigger EventName="Click">
   <cmd:EventToCommand Command="{Binding SomeCommand}" CommandParameter="{Binding}" PassEventArgsToCommand="True" />
   </i:EventTrigger>
  </i:Interaction.Triggers>
  <Button.Template>
   <ControlTemplate>
   <TextBlock Text="{Binding Title}" />
   </ControlTemplate>
  </Button.Template>
  </Button>
 </DataTemplate>
 </ListBox.ItemTemplate>
</ListBox>

1 个答案:

答案 0 :(得分:0)

如果你可以在ViewModel中有一个SelectedItem属性,你可以将它绑定到ListBox.Selecteditem,在SomeCommand实现中你可以设置ViewModel.SelectedItem,以便它反映到UI,你得到SelectionChanged调用。