How to Achieve Lazy Binding of Tab Page Controls in WPF?

前端 未结 3 1297
庸人自扰
庸人自扰 2020-12-29 16:28

I have an entity class. This entity has lots of properties and entity\'s data is shown to the user in several TabItems of a TabControl. I also impl

3条回答
  •  自闭症患者
    2020-12-29 17:04

    You don't have anything to do, that's the default behavior. The DataTemplate for a TabItem content won't be instantiated until this TabItem is selected


    EDIT: here's an example:

    
        
            
        
        
            
        
        
            
        
    
    
    ...
    
    
    
    

    In the code above, the TabControl will pick the appropriate DataTemplate based on the item type, and will render it only when that item is selected.


    EDIT 2: apparently you want to display the data of a single ViewModel on several pages. If you want the controls of each TabItem to lazily instantiated, you need to use the ContentTemplate property of each TabItem:

    
        
            
                
                    
                
            
        
        
            
                
                    
                
            
        
        
            
                
                    
                
            
        
    
    

提交回复
热议问题