I try to create a CustomControl ComboBox but i can´t change the Background color of the main ComboBox. I hope to creat a custom ComboBox with the same propertys of a normal ComboBox but with fix Colors.
Any Solution how can i change the Background Color of my custom ComboBox in the Generic.xaml?
Generic:
<Style TargetType="{x:Type local:CustomComboBox}">
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="Background" Value="Yellow" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border Background="Green"
BorderBrush="Green"
BorderThickness="50"
>
<DockPanel >
<ComboBox Background="Gold" BorderBrush="Gold"/>
</DockPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
To set the Backgroundcolor doesn´t work...
CodePudding user response:
You Can easily modify the default Style, to do that follow the next steps:
Insert your ComboBox.
Right click on ComboBox (In Design Area).
Edit Template ==> Edit a copy
Change the color of ComboBox.Static.Backgroun by yours
<LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#FFF0F0F0" Offset="0.0"/> <GradientStop Color="#FFE5E5E5" Offset="1.0"/> </LinearGradientBrush>
CodePudding user response:
Thanks for answering. Now i can change my color but i dont have a CustomControl. i think this is the full generic code but i dont have the class... :( Where can i get the full class of the ComboBox?
Generic:
<Style TargetType="{x:Type local:CustomComboBox}">
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="Background" Value="Yellow" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomComboBox}" >
<Border Background="Green"
BorderBrush="Green"
BorderThickness="2">
<ComboBox Style="{DynamicResource IdxComboBoxStyle}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I insert my style now but i cant work with it. The propertys have no effect.