WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?

前端 未结 8 1906
刺人心
刺人心 2020-11-28 06:39

(Note - this is a re-post as my first question got posted under wrong headline: Here Sorry!)

I have a standard WPF treeview and have bound items to view model classe

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 07:03

    It is really simple and this is how I handled double click at the TreeView:

    
    
          
            
                
                    
                
            
          
    
    

    System.Windows.Interactivity.dll is taken from C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\System.Windows.Interactivity.dll or by NuGet

    My view model:

    public class TreeViewModel : INotifyPropertyChanged
    {   
        private List departments;
        public TreeViewModel()
        {
            Departments = new List()
            {
                new Department("Department1"),
                new Department("Department2"),
                new Department("Department3")
            };
        }
    
        public List Departments
        {
            get
            {
                return departments;
            }
            set
            {
                departments = value;
                OnPropertyChanged("Departments");
            }
        }
    
        public void SomeMethod()
        {
            MessageBox.Show("*****");
        }
    }   
    

提交回复
热议问题