WPF-Listbox-ListboxItem双击事件实现-MVVM模式
2018-02-01 15:21
639 查看
<ListBox Name="EsCanSelectList" Grid.Row="1" ItemsSource="{Binding CanSelectList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=ExportName}"> <TextBlock.InputBindings> <MouseBinding Command="{Binding DataContext.EsCanSelectListMouseDoubleClickCommand, ElementName=w}" MouseAction="LeftDoubleClick"></MouseBinding> </TextBlock.InputBindings> </TextBlock> </DataTemplate> </ListBox.ItemTemplate> </ListBox> DataContext.EsCanSelectListMouseDoubleClickCommand C#后台鼠标左键双击事件命令实现 ElementName=w 数据源为窗口 w为窗口名称 Path=ExportName textblock显示数据来源 为CanSelectLis动态数据集合中的一个元素的属性 C#后台代码: /// <summary> /// 导出设置的数据模型 /// </summary> public class ExportModel { public int ExportID { get; set; } public string ExportName { get; set; } } 视图模型VeiwModel public class ExportSettingVeiwModel:ViewModels { private ObservableCollection<ExportModel> canSelectList; /// <summary> /// 可选择字段 /// </summary> public ObservableCollection<ExportModel> CanSelectList { get { return canSelectList; } set { canSelectList = value; RaisePropertyChanged("CanSelectList"); } } public ICommand EsCanSelectListMouseDoubleClickCommand { get; set; } public ExportSettingVeiwModel() { EsCanSelectListMouseDoubleClickCommand = new DelegateCommand(EsCanSelectList_MouseDoubleClick); CanSelectList = new ObservableCollection<ExportModel>(); ExportModel ceshi = new ExportModel(); ceshi.ExportID = 1; ceshi.ExportName = "ceshi"; CanSelectList.Add(ceshi); } public void EsCanSelectList_MouseDoubleClick() { if (CanSelectList.Count > 0 && _exportsetting.EsCanSelectList.SelectedIndex >= 0) { } //{ // int selectindex = _exportsetting.EsCanSelectList.SelectedIndex; // // ExportList.Add(CanSelectList[selectindex]); // CanSelectList.RemoveAt(selectindex); // if (selectindex < CanSelectList.Count) // { // _exportsetting.EsCanSelectList.SelectedIndex = selectindex; // } // else // { // _exportsetting.EsCanSelectList.SelectedIndex = selectindex - 1; // } //} } }
相关文章推荐
- WPF: 在 MVVM 设计中实现对 ListViewItem 双击事件的响应
- MVVM设计模式和在WPF中的实现(四) 事件绑定
- WPF中MVVM模式下的按钮事件实现和依赖项通知
- WPF: 在 MVVM 设计中实现对 ListViewItem 双击事件的响应
- WPF为ListBox添加ListBoxItem的双击事件
- 们只是「电脑玩物」 首页 实用技巧 免费资源 超好玩的游戏 软件推荐 IT技术 资讯 编程 其它 MVVM设计模式和WPF中的实现(四) 事件绑定 07net01.com 发布于 2015-10-08
- WPF: 在 MVVM 设计中实现对 ListViewItem 双击事件的响应
- MVVM设计模式和WPF中的实现 (事件绑定)
- MVVM设计模式和WPF中的实现(四)事件绑定
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
- Listbox 实现Item双击事件
- WPF ListView和ListBox等双击事件问题
- WPF MultiSelect模式下ListBox 实现多个ListBoxItem拖拽
- Prism初研究之使用Prism实现WPF的MVVM模式
- WPF+ListView+Linq+MVVM模式实现分页
- MVVM模式解析和在WPF中的实现(三)命令绑定
- Prism初研究之使用Prism实现WPF的MVVM模式
- MVVM-Light模式,在dataGrid的模板下,绑定事件不触发的原因已经服务端排序的实现
- WPF MVVM模式下实现ListView下拉显示更多内容
- MVVM-Light模式,在dataGrid的模板下,绑定事件不触发的原因已经服务端排序的实现