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

How to set a color different for each item

1 Answer 212 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gianfranco
Top achievements
Rank 1
Gianfranco asked on 29 Oct 2019, 09:05 AM

Hi everybody
I need to list a series of tools in a radcombobox where each color has a color associated with it.
The class of the tool is:
  public partial class ToolType
     {
         public int ToolTypeId {get; set; }
         public string Description {get; set; }
         public int Color {get; set; }
         public RecordState RecordState {get; set; }
         public string MachineryCode {get; set; }
         public int OwnerId {get; set; }

     }
where necessarily I had to transform the color to integer to be able to memorize it in SQL.

So I created a class to be able to use it in my RadCombobox to highlight on each item the color associated with my tool.

  public partial class ToolTypeForCmb
     {
         public int ToolTypeId {get; set; }
         public string Description {get; set; }
         public Brush Color {get; set; }
     }

So in my Xaml I created the RadCombobox:

 

<telerik:RadComboBox x:Name="cmbToolTypeForLoad" ItemsSource="{Binding ToolTypeForCmb}" DisplayMemberPath="Description"  Margin="46,29,0,0"      HorizontalAlignment="Left" VerticalAlignment="Top" Width="421"  Height="48"  >
                    <ComboBoxItem>
                        <Style TargetType="ComboBoxItem">
                            <Setter Property="Background" Value="{Binding Color}"/>
                        </Style>
                    </ComboBoxItem>
 </telerik:RadComboBox>

 

 

 

 

 List<ToolType> toolTypes = toolTypeService.GetAll(MachineryCode);
            List<ToolTypeForCmb> toolTypeForCmb = new List<ToolTypeForCmb>();
            foreach (ToolType toolType in toolTypes)
            {
                ToolTypeForCmb ttfcmb = new ToolTypeForCmb();
                ttfcmb.Color = UtilityService.ConvertIntToColorBrush(toolType.Color);
                ttfcmb.Description = toolType.Description;
                ttfcmb.ToolTypeId = toolType.ToolTypeId;
                toolTypeForCmb.Add(ttfcmb);
            }
            cmbToolTypeForLoad.ItemsSource = toolTypeForCmb;

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Gianfranco
Top achievements
Rank 1
answered on 29 Oct 2019, 09:40 AM

Sorry

this post is to be deleted.

Tags
ComboBox
Asked by
Gianfranco
Top achievements
Rank 1
Answers by
Gianfranco
Top achievements
Rank 1
Share this question
or