2016-04-14 103 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功能 –