WPF - MVVM - 如何将ComboBox的Selectchange事件binding到ViewModel
2014-05-07 12:48
399 查看
将所有的事件,属性,都映射到ViewModel中。好处多多,以后开发尽量用这种模式。
解决方法:
使用System.Windows.Interactivity.dll,添加该dll到项目引用
ComboBox映射的代码:
解决方法:
使用System.Windows.Interactivity.dll,添加该dll到项目引用
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
ComboBox映射的代码:
<ComboBox VerticalAlignment="Center" HorizontalAlignment="Left" MinWidth="120" Margin="10,0,0,0" x:Name="cboTest" DisplayMemberPath="FamilyName" SelectedValuePath="IdFamily" IsReadOnly="True" ItemsSource="{Binding ListFamily}" SelectedValue="{Binding Path=ViewModel.SelectedFamilyNameID, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" Validation.ErrorTemplate="{x:Null}" Visibility="{Binding ComboBoxVisibility}" > <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding FamilySelectionChangedCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext}"/> </i:EventTrigger> </i:Interaction.Triggers> </ComboBox>
相关文章推荐
- 第四周作业
- 【python】中文乱码问题
- mysql replication 学习笔记
- 创业失败的七个原因及解决之道
- UVa - 10106 - Product
- shell特殊字符
- 在linux环境下部署伪分布式hadoop遇到的问题
- C语言程序所占内存分类
- UEditor上传图片等附件都出现红叉
- 第三周作业
- linux压缩包解压缩
- 静态链表
- SQL一列三行变成一列一行
- java JDBC(二):Statement、ResultSet、PreparedStatement
- Vim常用配置(~/.vimrc)(转载)
- 网络垃圾的来源和处理措施详解
- POJ 2195 二分图最小权匹配KM算法
- XCODE插件 之 Code Pilot 无鼠标化
- matlab基础知识 randperm()的用法
- 20140506朗沃(1)