tags:

views:

18

answers:

1

Hi, all!

I have a ListBox with Button in ItemTemplate. When I press a Button, some Command fired. I want the ListBox to fire SelectionChanged event when Button Click event happen. How shoult I fire ListBox SelectionChanged event and pass appropriate context?

<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>
A: 

If you can have a SelectedItem property in the ViewModel you can TwoWay bind that to the ListBox.Selecteditem and in the SomeCommand implementation you can set the ViewModel.SelectedItem so that it reflects to the UI and you get SelectionChanged call.

Jobi Joy