Select node in treeView on right click MVVM

前端 未结 2 612
孤街浪徒
孤街浪徒 2021-01-13 09:12

I want to select a node of tree view on right click. I am using MVVM pattern and don\'t want to achieve this in code behind. Here is my XAML for tree view.

&         


        
2条回答
  •  滥情空心
    2021-01-13 09:27

    You can use interactivity

    xmlns:interactive="http://schemas.microsoft.com/expression/2010/interactivity"
    

    The xaml:

    
                
                    
                        
                     
                
                
                    
                        
                    
                    
                        
                    
                    
                        
                            
                                
                            
                            
                                
                                    
                                
                            
                            
                        
                    
                
          
    

    And in the viewModel:

     private void ExecuteTreeViewRightClickCommand(object obj)
            {
                ((TreeViewItem)obj).IsSelected = true;
                SelectedSlide = ((TreeViewItem)obj).Header as SlideModel;
            }
    

提交回复
热议问题