Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF combobox selected item text not grayed out when IsEnabled=False and IsEditable = False

Tags:

.net

wpf

With the following code the text of the selected item of the combo box shows normally (i.e. in black). I want it to be grayed out when the control is disabled. However, if I set IsEditable=True then it is grayed out, but I don't want it to be editable.

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ComboBox Width="150" Height="23" IsEnabled="False" SelectedIndex="0" IsEditable="False">
            <TextBlock>Hello</TextBlock>
            <TextBlock>World</TextBlock>
        </ComboBox>
    </Grid>
</Window>
like image 417
Shane Avatar asked Sep 20 '25 11:09

Shane


1 Answers

To Fix combobox item color to gray when disabled, do the below, this will fix all the combobox in your UI.

Paste this inside <Window.Resources> tag in your Xaml code:

<Style TargetType="{x:Type ComboBox}">
    <Style.Triggers>
        <Trigger Property="IsEnabled"
                 Value="False">
            <Setter Property="Foreground"
                    Value="Gray"/>
        </Trigger>
    </Style.Triggers>
</Style>
like image 135
Chandraprakash Avatar answered Sep 23 '25 08:09

Chandraprakash