Good day, I have two errors that I can not solve. Thanks in advance for any help!
When you hover the mouse over the ComboBox, it is highlighted in color. But if you change the Background from the ComboBox in the XAML constructor, it is no longer highlighted in color.
I need to bind the color of the Background and Border ComboBox to the Background and Border of the ComboBox drop-down list. But so that when you hover the mouse over the ComboBox, the drop-down list does not change the color of the Background and Border to the color of the ComboBox selection.
Code:
<ControlTemplate x:Key="ComboBoxToggleButtonTemplate" TargetType="ToggleButton"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="20" /> </Grid.ColumnDefinitions> <Border Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/> <Path Grid.Column="1" Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 Z" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="Black"/> </Grid> </ControlTemplate> <Style TargetType="ComboBox"> <Setter Property="Foreground" Value="WhiteSmoke"/> <Setter Property="Background" Value="Gray"/> <Setter Property="BorderBrush" Value="Black"/> <Setter Property="BorderThickness" Value="3"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="20" /> </Grid.ColumnDefinitions> <ToggleButton Grid.ColumnSpan="2" ClickMode="Press" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Template="{StaticResource ComboBoxToggleButtonTemplate}" IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/> <ContentPresenter Margin="5, 3, 0, 3" IsHitTestVisible="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding ComboBox.SelectionBoxItem}" ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/> <Popup AllowsTransparency="True" PopupAnimation="Slide" IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"> <Grid MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}"> <Border Background="White" BorderBrush="Black" BorderThickness="1"/> <ScrollViewer Margin="0,1,1,1"> <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" /> </ScrollViewer> </Grid> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Black"/> <Setter Property="Background" Value="Yellow"/> <Setter Property="BorderBrush" Value="Aqua"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>