В моем приложении WPF мне нужно установить цвет фона моего комбинированного списка.
Пример
Как вы видите в прикрепленном файле, я установил thw backgroundцвет синий как (в коде позади):
_combobox.Background = Brushes.DodgerBlue;
Я также установил триггеры для обработки события при выборе элементов (установите стиль для ComboBox и ComboBoxItem:
<Style x:Key="CmbStyleItem" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="gd" Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}, Path=Background}" Padding="4,6,2,2">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ComboBoxItem.IsMouseOver" Value="True">
<Setter TargetName="gd" Property="Background" Value="#E7E2E2" />
<Setter TargetName="gd" Property="TextElement.Foreground" Value="#000000"/>
</Trigger>
<Trigger Property="ComboBoxItem.IsSelected" Value="True">
<Setter TargetName="gd" Property="Background" Value="#D6D6D6" />
<Setter TargetName="gd" Property="TextElement.Foreground" Value="#000000" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Height" Value="27" />
<Setter Property="Padding" Value="4,6,2,2" />
<Setter Property="FontFamily" Value="{StaticResource fntConsole}" />
<Setter Property="Typography.Capitals" Value="AllSmallCaps"/>
<Setter Property="FontSize" Value="13.55" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ItemContainerStyle" Value="{DynamicResource CmbStyleItem}"/>
</Style>
В принципе, я не могу установить цвет фона выбранного элемента, например, во вложении, элемент "Tav1800x650x18". Любые подсказки?