2010-10-27 51 views
0

我在ItemTemplate中有一個帶按鈕的ListBox。當我按下按鈕時,一些命令被解僱。當Button Click事件發生時,我想讓ListBox觸發SelectionChanged事件。我該如何激發ListBox SelectionChanged事件並傳遞適當的上下文?在ItemTemplate中帶按鈕的ListBox:在Button上觸發SelectedChanged點擊

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

回答

0

如果你可以有一個SelectedItem屬性在視圖模型可以綁定是雙向的ListBox.Selecteditem並在SomeCommand實施可以設置ViewModel.SelectedItem,以便它反映到UI,你會得到的SelectionChanged呼叫。