Using Picture or Icon instead of DataGridCheckBoxColumn in WPF

后端 未结 1 1878
甜味超标
甜味超标 2021-01-21 04:03

I want to change the CheckBox which is inside of a DataGridColumn into an image when it is checked and another when it is unchecked, How can i do ? Ps: My DataGridCheckBoxColumn

1条回答
  •  被撕碎了的回忆
    2021-01-21 04:25

    Use the ElementStyle and EditingElementStyle properties to create and set a different Template for the CheckBox which fits that.

    e.g.

    
        
            
                                
                            
                        
                    
                
            
        
    
    

    This makes the column display an image based on IsChecked, the URIs are just hardcoded and the CheckBox is disabled because editing in the ElementStyle does not change any properties on the bound object. Its only purpose is to display the approriate image.

    (The EditingElementStyle is not set here so if the user clicks the cell again to edit it a normal CheckBox appears which can be checked or unchecked.)

    Screencap

    0 讨论(0)
提交回复
热议问题