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
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/.
Hi Dinko,
Thanks for your response. I tried this approach but it is still not working.
Regards,
Aanchal
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/.
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
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/.
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
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/.