context menu for removing items in listview

后端 未结 3 913
轮回少年
轮回少年 2021-02-02 17:23

I have a ListView which displays a list of string values. I want to add a context menu entry for each item in the list to remove the selected item. My XAML looks like this:

3条回答
  •  长情又很酷
    2021-02-02 17:59

    ContextMenus are disconnected, you cannot use ElementName bindings. One workaround would be using Binding.Source and x:Reference which requires you to extract parts that use it to be in the resources (due to cyclical dependency errors). You can just put the whole context menu there.

    An example:

    
        
            
                
            
        
        
            
        
    
    

提交回复
热议问题