如何更改组合框背景

How to change comboboxes background

如何更改我的组合框背景我已经能够使用新的项目模板为项目做这件事 但不适用于组合框本身,因为画笔属性不适用于该组合框 i want to change this

组合框:

<ComboBox x:Name="Bil_box" HorizontalAlignment="Center" Margin="57,33,968,799" VerticalAlignment="Center" Width="151" Height="40" Foreground="#FF00FB0B" Background="#FF303030" ItemTemplate="{StaticResource cmbTemplate}">
    <ComboBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="#FF303030" />
    </ComboBox.Resources>
</ComboBox>

模板:

<DataTemplate x:Key="cmbTemplate">
    <WrapPanel Margin="0 5 0 5" Height="30">
        <Image Width="20" Height="20" Stretch="Fill" Source="{Binding Billed}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
        <Label Content="{Binding bilmærke}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="12" Foreground="#FF00FB0B"/>
        <Label Content="{Binding Krydsmål}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="12" Foreground="#FF00FB0B"/>
    </WrapPanel>
</DataTemplate>`

您要查找的项目是一个名为 templateRoot

Border 控件

您首先必须为组合框编辑一个模板(如果您还没有模板,请编辑一份)。然后寻找名为 toggleButtonToggleButton 控件。

右击Edit this Template(edit current)应该可以找到我上面提到的边框。更改 Background 就可以了。

代码对于 post 来说太长了(由于模板的大小),但这是相关位的片段(我已将背景更改为 红色)

<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="ClickMode" Value="Press"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="Red" SnapsToDevicePixels="true">
                        <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
                            <Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
                        </Border>
                    </Border>