WPF: How to customize SelectionBoxItem in ComboBox

前端 未结 4 723
执念已碎
执念已碎 2020-12-01 19:48

I want to display a custom template/item as selected item in ComboBox (this item does not actually exist in the list of items and is updated differently). This does not even

4条回答
  •  猫巷女王i
    2020-12-01 19:55

    I would do it like this:

    
    
      
        ...
      
    
      
        ...
      
    
      
        
        
          
            
          
        
      
    
    
    
    ...
    
    
    

    The reason this works is that CombinedTemplate normally just uses NormalItemTemplate to present its data, but if there is no ComboBoxItem ancestor it assumes it is in the selection box so it uses SelectionBoxTemplate.

    Note that the three DataTemplates could be included in any level of ResourceDictionary (not just at the Window level) or even directly within the ComboBox, depending on your preference.

提交回复
热议问题