2016-04-14 104 views
1

如何改变了我的组合框的背景我已经能够用新的ItemTemplate 做的项目,但不是组合框本身作为画笔属性不为 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>` 

回答

0

你要找的该项目a Border control called templateRoot

您首先必须为您的ComboBox编辑一个模板(如果您还没有编辑一个副本)。然后寻找名为toggleButtonToggleButton控件。

右键单击并编辑这个模板(编辑当前),你应该能够找到我上面提到的边框。改变Background,你很好走。

代码过长后(由于模板的大小),但这里的相关位的片段(我已经改变了背景

<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> 
+0

THX奏效 –

+0

有没有其他的方式来做到这一点,因为你只能做一个没有PresentationFramework.Aero2,至少在win7上给我一些错误,因为只有win8和above功能 –