你如何处理MVVM中的ComboBox SelectionChanged?选择已更改的事件未触发。 [英] How do you handle a ComboBox SelectionChanged in MVVM? Selection changed events are not firing.
问题描述
ComboBox 1
< combobox grid.column =1grid.row =1height =23horizontalalignment =Centermargin =2,2,0,0name =comboBoxSerververticalalignment =Topwidth =156 itemssource ={Binding Path = ServerNameList,Mode = OneWay}selectedindex =0selecteditem ={Binding SelectedIndex}selectionchanged =comboBoxServer_SelectionChangedtext ={Binding selectedServer,Mode = OneWayToSource,UpdateSourceTrigger = PropertyChanged}> ;
< i:Interaction.Triggers>
< i:EventTrigger EventName =SelectionChanged>
< i:InvokeCommandAction Command ={Binding serverCommand}CommandParameter ={Binding ElementName = comboBoxServer,Path = SelectedValue}/>
< / i:EventTrigger>
< / i:Interaction.Triggers>
< / combobox>
ComboBox 2
< ComboBox Grid.Column =1Grid.Row =2Height =23HorizontalAlignment =CenterMargin =2,2,0,0Name =comboBoxDBNameVerticalAlignment =TopWidth =156 ItemsSource ={Binding Path = DBNameList,Mode = OneWay}SelectedItem ={Binding serverSelected,Mode = TwoWay}>
< / ComboBox>
我希望基于第一个组合框选择,我的第二个组合框被填充。
检查以下答案,
答
ComboBox 1
< combobox grid.column="1" grid.row="1" height="23" horizontalalignment="Center" margin="2,2,0,0" name="comboBoxServer" verticalalignment="Top" width="156" itemssource="{Binding Path=ServerNameList, Mode=OneWay}" selectedindex="0" selecteditem="{Binding SelectedIndex}" selectionchanged="comboBoxServer_SelectionChanged" text="{Binding selectedServer, Mode=OneWayToSource,UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
< i:InvokeCommandAction Command="{Binding serverCommand}" CommandParameter="{Binding ElementName=comboBoxServer, Path=SelectedValue}"/>
< /i:EventTrigger>
</i:Interaction.Triggers>
</combobox>
ComboBox 2
< ComboBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Center" Margin="2,2,0,0" Name="comboBoxDBName" VerticalAlignment="Top" Width="156" ItemsSource="{Binding Path=DBNameList, Mode=OneWay}" SelectedItem="{Binding serverSelected, Mode=TwoWay}" >
< /ComboBox>
I want that based on first combobox selection, my second combobox gets populated.
Hi, Check the following answer,
Answer
这篇关于你如何处理MVVM中的ComboBox SelectionChanged?选择已更改的事件未触发。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!