I have a combobox, using databinding and MVVM pattern. Everytime the user changes the selection, I added an event trigger, and a command is executed. the code is the following:
<ComboBox x:Name="myComboBox" Width="150" ItemsSource="{Binding Items}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
开发者_开发技巧 </DataTemplate>
</ComboBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding LoadCommand}" CommandParameter="{Binding SelectedItem, ElementName=myComboBox}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
the problem is that the parameter it passes is always null.
I changed the parameter from SelectedItem to SelectedIndex, this way I get the parameter and it is not null. Then i get my object using the index.
精彩评论