How to display context menu for treeview item in a hierarchial data template in wpf

后端 未结 4 1881
情书的邮戳
情书的邮戳 2020-12-16 16:22

How to display context menu for tree view item in wpf using the hierarchical data template? How to display context menu only for CountryTemplate:

  

        
4条回答
  •  情话喂你
    2020-12-16 17:13

    One of the reasons why context menus do not work as cleanly as they could is because by default, they are in a different visual tree to everything else, so the DataContext cannot be found.

    The key insight is to create a

    Then, hook the context menu up anywhere you want, without running into issues caused by different visual trees.

    Example 1:

    
        
            
    
    

    Example 2:

    
                       
          
    

提交回复
热议问题