This is a migrated thread and some comments may be shown as answers.

telerik:RadComboBox not changing text color for selected value when disabled.

7 Answers 109 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aanchal
Top achievements
Rank 1
Aanchal asked on 23 Dec 2020, 06:01 AM

Hi,

Below is my code snippet for RadComboBox that I am using:

<telerik:RadComboBox ItemsSource="{Binding xyz}"
                                                     IsEnabled="False"
                                                     IsEditable="False"
                                                     HorizontalAlignment="Stretch"
                                                     SelectedIndex="1" 
                                                     Width="Auto">

When I apply the below style to change foreground color when disabled, it is not working:

<telerik:RadComboBox.TextBoxStyle>
                                                        <Style TargetType="TextBox">
                                                            <Style.Triggers>
                                                                <Trigger Property="IsEnabled" Value="False">
                                                                    <Setter Property="Foreground" Value="Gray" />
                                                                </Trigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </telerik:RadComboBox.TextBoxStyle>

 

This trigger only works when I set IsEditable-"True" and IsFilteringEnabled="True"

 

Is there any way that I can change the font color even when IsEditable-"False"?

 

Thanks,

Aanchal

7 Answers, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 25 Dec 2020, 02:31 PM

Hello Aanchal,

Thank you for the provided code snippet.

This behavior is expected. The TextBox inside the RadComboBox will appear only when the IsEditing property is set to true. Otherwise, a TextBlock element is present. In non-editing control, you can directly target and set the Foreground property of the control.

<telerik:RadComboBox.Style>
    <Style TargetType="telerik:RadComboBox">
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
        </Style.Triggers>
    </Style>
</telerik:RadComboBox.Style>

I hope this approach will work for you.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Aanchal
Top achievements
Rank 1
answered on 28 Dec 2020, 06:12 AM

Hi Dinko,

Thanks for your response. I tried this approach but it is still not working.

Regards,

Aanchal

0
Martin Ivanov
Telerik team
answered on 30 Dec 2020, 01:06 PM

Hello Aanchal,

The approach suggested by Dinko works, but only for part of the Telerik themes. For example, it will work in the default Office_Black, but it won't work in the Fluent theme. An alternative approach that should work regardless of the theme is to get the element that shows the text in code and define the trigger there.

private void RadComboBox_Loaded(object sender, RoutedEventArgs e)
{
	var comboBox = (RadComboBox)sender;
	var button = comboBox.FindChildByType<RadToggleButton>();
	var style = new Style(typeof(RadToggleButton));
	style.BasedOn = button.Style;
	var trigger = new Trigger() { Property = RadToggleButton.IsEnabledProperty, Value = false };
	trigger.Setters.Add(new Setter(RadToggleButton.ForegroundProperty, Brushes.Red));
	style.Triggers.Add(trigger);            
	button.Style = style;
}

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Aanchal
Top achievements
Rank 1
answered on 31 Dec 2020, 07:27 AM

Hi Martin,

I tried this, but getting a System.NullReferenceException at below statement:

var button = comboBox.FindChildByType<RadToggleButton>();

this statement is returning null.

I tried to fetch TextBox and TextBlock also but it is also returning null.

Do we need to fetch some other child element of combobox?

 

Regards,

Aanchal

0
Martin Ivanov
Telerik team
answered on 04 Jan 2021, 06:41 AM

Hello Aanchal,

The error in this case can appear if you are using NoXaml dlls without merging the required theme resources. To resolve it, make sure that Xaml dlls are used in the project, or if you use NoXaml then merge the theme ResourceDictionaries as shown in the Setting a Theme article.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Aanchal
Top achievements
Rank 1
answered on 04 Jan 2021, 04:17 PM

Hi Martin,

I believe I am using Xaml dlls only, I checked it in the document suggested by you.

Attaching the screenshot of the dll properties.

Regards,

Aanchal

0
Martin Ivanov
Telerik team
answered on 05 Jan 2021, 09:04 AM

Hello Aanchal,

You can also double check the Telerik.Windows.Controls.Input.dll. Additionally, I've attached a sample project with referenced Telerik Xaml dlls. I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ComboBox
Asked by
Aanchal
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Aanchal
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or