Context Menu for XAML Treeviewitem (Distinguished by different attributes)

后端 未结 3 1997
太阳男子
太阳男子 2021-02-04 00:40

In XAML, how do you define a context menu for treeviewitems that are distinguished by different attributes?

3条回答
  •  故里飘歌
    2021-02-04 01:29

    XAML

    
      
        
          
          
        
        
          
          
          
          
          
          
          
          
        
      
    
    

    C-sharp

    private void SolutionTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e)
    {
        TreeViewItem SelectedItem = SolutionTree.SelectedItem as TreeViewItem;
        switch (SelectedItem.Tag.ToString())
        {
            case "Solution":
                SolutionTree.ContextMenu = SolutionTree.Resources["SolutionContext"] as System.Windows.Controls.ContextMenu;
                break;
            case "Folder":
                SolutionTree.ContextMenu = SolutionTree.Resources["FolderContext"] as System.Windows.Controls.ContextMenu;
                break;
        }
    }
    
        

    提交回复
    热议问题