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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With