Styling the indeterminate state of a WPF checkbox

后端 未结 9 1909
情话喂你
情话喂你 2021-02-04 07:30

I want to style the indeterminate state of a WPF checkbox. We have a treeview control with checkboxes, and we want the indeterminate state to represent that some descendants are

9条回答
  •  借酒劲吻你
    2021-02-04 08:00

    Call me crazy, but I've actually reimplemented standard Aero checkbox in pure XAML. If you want to customize Aero checkbox, it's a good starting point. You can find other styles in my repository on GitHub (specific commit, in case files are moved).

    BulletCommon.xaml (common resources for CheckBox and RadioButton)

    
    
        
    
        
        
        
        
        
        
        
        
        
        
            
            
            
        
        
        
            
            
            
        
        
        
            
            
        
        
            
            
        
        
            
            
        
        
        
            
            
        
        
            
            
        
        
            
            
        
        
            
            
        
    
        
    
        
    
        
    
    
    

    CheckBox.xaml (resources for CheckBox)

    
    
        
            
        
    
        
    
        
        
        
        
        
        
        
        
        
        
            
            
            
        
        
            
            
            
        
        
            
            
            
        
        
        
            
            
            
        
        
            
            
            
        
        
            
            
            
        
        
        
            
            
            
            
        
        
            
            
            
            
        
        
            
            
        
    
        
    
        
            
                
                
                
                
                
                
                
            
        
    
        
    
        
    
    
    

    Notes:

    1. {xx:SystemBrush ControlText} is a shortcut for {DynamicResource {x:Static SystemColors.ControlTextBrushKey}}. You can either use that shortcut or just find and replace with regex.

    2. RTL, animations, weird cases are not supported.

    3. This style is slower than using BulletChrome which is heavily optimized.

提交回复
热议问题