Bind Any XML document to WPF TreeView

后端 未结 3 400
长发绾君心
长发绾君心 2021-01-02 17:01

I would like to bind any XML document to WPF TreeView using TypeConverter.

My original solution was to use recursion, but when document is large UI is heavily tied u

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 17:31

    It works for other node types with a few simple modifications. First, HierarchicalDataTemplate.ItemsSource Binding XPath must be changed to "child::node()|attribute::*" to allow any child node and any attribute. Then, add DataTriggers for other NodeTypes. The example below worked for me. NOTE that i added icons for various NodeTypes, you might want to remove them:

            
            
            
            
            
            
            
            
                
            
            
                
                    
                    
                
                
                    
                    
                
                
                    
                    
                    
                    
                
                
                    
                    
                
                
                    
                    
                
                
                    
                    
                
            
        
    

提交回复
热议问题