wpfvb.netxamlradcombobox

How to change foreground of combobox on disabled state?


I want to block user to edit/select combobox. I tried using cmbbox.IsReadOnly = True and cmbbox.IsEditable = False which allows user to change selection by alt and arrow' keys. cmbbox.isEnabled = False works and my requirement is to change combobox foreground color to 'Black' when it is disabled. Can anyone please help me to fix it?

In XAML:

<telerik:RadComboBox Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2"  x:Name="combobox1" IsEditable="True" IsFilteringEnabled="True" ItemsSource="{Binding}" TabIndex="7" Style="{ DynamicResource DropDownListStyle }" IsTabStop="True" KeyboardNavigation.TabNavigation ="Local" SelectAllTextEvent="None" Height="23" Margin="0,0,0,2" VerticalAlignment="Center"/>

In Codebehind:

combobox1.IsEnabled = False

In Style:

 <Style x:Name="DropDownListStyle" x:Key="DropDownListStyle" TargetType="telerik:RadComboBox" >
                <Setter Property="Foreground" Value="#FF000000"/>
                <Setter Property="BorderBrush" Value="#ffcccccc"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="HorizontalContentAlignment" Value="Left" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontWeight" Value="Thin"/>
                <Setter Property="FontFamily" Value="Trebuchet MS"/>
                <Setter Property="Panel.ZIndex" Value="10" />
                <Setter Property="Height" Value="23" />
                <!--  <Setter Property="Focusable" Value="True"/> -->
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="White"/>
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

Solution

  • I have fixed it by setting IsReadonly = True property to combobox and triggering PreviewKeyDown event.

    combobox1.IsReadonly = True
    

    and

    Private Sub combobox1_PreviewKeyDown(sender As Object, e As Windows.Input.KeyEventArgs) Handles combobox1.PreviewKeyDown
            If combobox1.IsReadOnly Then
                If e.Key = Key.Tab Then
                    e.Handled = False
                Else
                    e.Handled = True
                End If
            End If
    End Sub