Changing the font color on a disabled checkbox in WPF

13,020

you need a trigger

check this answer: WPF Button IsEnabled Based on ComboBox Selection Overwriting default style

this is pretty much the same way

Share:
13,020

Related videos on Youtube

Joel Barsotti
Author by

Joel Barsotti

Updated on April 16, 2022

Comments

  • Joel Barsotti
    Joel Barsotti about 2 years

    I'm hoping this is an easy answer, as I'm just learning WPF.

    I've got a resource dictionary that defines all our styles. Currently the checkbox style looks like:

    <Style x:Key="StandardCheckboxStyle" TargetType="{x:Type CheckBox}">
        <Setter Property="Foreground" Value="{Binding Source={StaticResource BrandInfo}, XPath=//Colors/@TextColor}"/>
        <Setter Property="FontSize" Value="12"/>
    </Style>
    

    The XPath stuff is so that an end user could theoretically swap out the color pallete. There is an XML file obviously backing the colors we use. Currenlty TextColor is white and the background for the app is a darkish gray. Obviously when a checkbox is disabled and the text greys out we lose alot of contrast.

    So how do you changed the text color of a checkbox when it's set IsEnabled="False"?