WPF Context Menus in Caliburn Micro

前端 未结 2 2057
旧巷少年郎
旧巷少年郎 2020-12-29 08:39

I\'m trying to get a context menu within a ListBox ItemTemplate to call a method on the parent view model, passing in the item that was clicked on as a parameter. I have thi

2条回答
  •  悲哀的现实
    2020-12-29 09:10

    Using the information I found on the Caliburn Micro site I modified your XAML to look like this:

             
                    
            
                
                    
                        
                            
                                
                                
                            
                        
    
                        
                    .. text..
                        
                    
                
            
        
    
    

    And my view model:

        public List ListBoxItems { get; set; }
        public ShellViewModel()
        {
            ListBoxItems = new List {"One", "Two", "Three"};          
        }
    
        public void Open(object source)
        {
            MessageBox.Show((string) source);
        }
    

    Open was successfully called with the appropriate strings from the list box.

提交回复
热议问题