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

WPF telerik:RadComboBox forecolor doesn't stay colored when selecting it

3 Answers 205 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 15 Oct 2019, 08:31 PM

I have the following .xaml and it correctly colorizes the foreground on specific items when a certain condition is met (Impinged = True).
However, when I select that item, it doesn't maintain the color. I attempted the following suggestion on this thread but it didn't work. Either because I am working with Telerik or something else.

I tried this but didn't work:

https://stackoverflow.com/questions/49936272/combobox-change-selected-item-background-color-by-trigger-condition

 

<telerik:GridViewDataColumn.CellTemplate>
  <DataTemplate>
     <telerik:RadComboBox
        x:Name="cbLowBand"
        DisplayMemberPath="Name"
        ItemsSource="{Binding DataContext.LowBandItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}}}"
        SelectedItem="{Binding SelectedLowItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        Style="{StaticResource MyCustomStyle}"

        <telerik:RadComboBox.ItemContainerStyle>
       <Style TargetType="telerik:RadComboBoxItem">
              <Style.DataTriggers>
         <DataTrigger Binding="{Binding IsImpinged}", Value="True">
        <Setter Property="Foreground" Value="Red" />
        <Setter Property=ToolTip", Value="{Binding ImpingedTooltip}" />
         </DataTrigger>
      </Style.DataTriggers>
    </Style> 
    </telerik:RadComboBox.ItemContainerStyle>

       <!--other non related stuff>
       <telerik:EventToCommandBehavior.EventBindings>
     <telerik:EventBinding
              Command="{Binding DataContext.LowBandItem, RelativeSource=...........

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Dinev
Telerik team
answered on 16 Oct 2019, 03:32 PM

Hi John,

Thank you for the code snippet.

I followed your approach but was unable to replicate the behavior you're describing. Here's what I did - I've placed a RadComboBox inside a GridViewDataColumn and based on a condition, set a red Foreground of the RadComboBoxItem, which, as you said, is correctly colorized. When I click on the item, the dropdown menu is closed and this item is selected. When I open it again the selected item's Foreground is still red which is expected. I have tried this approach with several different themes.

I noticed one part that may potentially cause an unexpected behavior. It is that the SelectedItem is coming from the RadComboBox's DataContext, while the ItemsSource is coming from the DataContext of the RadGridView. Could you, please confirm that is intended?

Attached, you can find a sample project demonstrating the above description. Please, review it and let me know if I am missing a part from your setup.

Regards,
Dimitar Dinev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
John
Top achievements
Rank 1
answered on 16 Oct 2019, 04:23 PM
I was able to actually do it by templatizing the SelectionTemplate. But your suggestion is good too.
0
Dimitar Dinev
Telerik team
answered on 17 Oct 2019, 01:55 PM

Hello John,

I am glad to hear that you managed to achieve the desired result.

If you have any further queries, don't hesitate to contact us again.

Regards,
Dimitar Dinev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
Dimitar Dinev
Telerik team
John
Top achievements
Rank 1
Share this question
or