你如何处理MVVM中的ComboBox SelectionChanged?选择已更改的事件未触发。 [英] How do you handle a ComboBox SelectionChanged in MVVM? Selection changed events are not firing.

查看:559
本文介绍了你如何处理MVVM中的ComboBox SelectionChanged?选择已更改的事件未触发。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ComboBox 1



< combobox grid.column =1grid.row =1height =23horizo​​ntalalignment =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 =23Horizo​​ntalAlignment =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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆