开发者

silverlight combobox invokecommandaction on selectionchanged event cannot pass parameter

开发者 https://www.devze.com 2023-04-11 12:55 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消