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;