Is there a way to use data-template inheritance in WPF?

前端 未结 2 1134
攒了一身酷
攒了一身酷 2020-11-27 14:09

Is it possible to have DataTemplate composition or inheritance (similar to \"BasedOn\" in Styles)? There are 2 instances where I need that.

  1. For

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 14:38

    The only thing that I have found do to for this kind of thing is this:

    
      
    
    
      
    
    
      
        
        
      
    
    

    Basically this creates a "common" template that can be referenced using a key (BaseClass in this case). Then we define the real DataTemplate for the base class, and any derived classes. The derived class template would then add it's own "stuff".

    There was some discussion about this on msdn a while back, but no one came up with a better solution that I saw.

提交回复
热议问题