WPF-Listbox-ListboxItem双击事件实现-MVVM模式


                            
                                
                                    
                                        
                                            
                                        
                                    
                                
                            
                        
DataContext.EsCanSelectListMouseDoubleClickCommand   C#后台鼠标左键双击事件命令实现
ElementName=w    数据源为窗口  w为窗口名称
Path=ExportName  textblock显示数据来源   为CanSelectLis动态数据集合中的一个元素的属性
C#后台代码:
    /// 
    /// 导出设置的数据模型
    /// 
    public class ExportModel
    {
        public int ExportID { get; set; } 
        public string ExportName { get; set; }
    }
  视图模型VeiwModel
public class ExportSettingVeiwModel:ViewModels
    {
        private ObservableCollection canSelectList;
        /// 
        /// 可选择字段
        /// 
        public ObservableCollection 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 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-Listbox-ListboxItem双击事件实现-MVVM模式)