2017-02-17 66 views
1

我正在使用WPF扩展CheckComboBox。 我在其中修改了几个样式选项的应用程序资源中有一个模板,但是我找不到如何更改复选框颜色。CheckComboBox框颜色

任何人有想法?

这里是我使用的模板:

<Style x:Key="CheckComboBoxStyle1" TargetType="{x:Type xctk:CheckComboBox}"> 
    <Setter Property="Foreground" Value="White"/> 
    <Setter Property="Background" Value="White"/> 
    <Setter Property="BorderBrush" Value="White"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="Padding" Value="2"/> 
    <Setter Property="ScrollViewer.CanContentScroll" Value="True"/> 
    <Setter Property="ScrollViewer.PanningMode" Value="Both"/> 
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
    <Setter Property="VerticalContentAlignment" Value="Center"/> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type xctk:CheckComboBox}"> 
       <Grid x:Name="MainGrid" SnapsToDevicePixels="True"> 
        <Popup x:Name="PART_Popup" AllowsTransparency="True" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" StaysOpen="False"> 
         <Grid MinWidth="{Binding ActualWidth, ElementName=MainGrid}"> 
          <Border x:Name="DropDownBorder" BorderBrush="White" BorderThickness="1" Background="#676767" MaxHeight="{Binding MaxDropDownHeight, RelativeSource={RelativeSource TemplatedParent}}"> 
           <ScrollViewer x:Name="DropDownScrollViewer"> 
            <Grid RenderOptions.ClearTypeHint="Enabled"> 
             <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0" Background="#676767"> 
              <Rectangle x:Name="OpaqueRect" Fill="#676767" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/> 
             </Canvas> 
             <ItemsPresenter x:Name="PART_ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
            </Grid> 
           </ScrollViewer> 
          </Border> 
         </Grid> 
        </Popup> 
        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="#676767"/> 
        <ToggleButton x:Name="PART_DropDownButton" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Content="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"> 
         <ToggleButton.IsHitTestVisible> 
          <Binding Path="IsDropDownOpen" RelativeSource="{RelativeSource TemplatedParent}"> 
           <Binding.Converter> 
            <xctk:InverseBoolConverter/> 
           </Binding.Converter> 
          </Binding> 
         </ToggleButton.IsHitTestVisible> 
         <ToggleButton.Style> 
          <Style TargetType="{x:Type ToggleButton}"> 
           <Setter Property="OverridesDefaultStyle" Value="True"/> 
           <Setter Property="IsTabStop" Value="False"/> 
           <Setter Property="Focusable" Value="False"/> 
           <Setter Property="Padding" Value="2"/> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type ToggleButton}"> 
              <xctk:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="0" RenderNormal="False" RenderMouseOver="{Binding IsMouseOver, ElementName=PART_DropDownButton}" RenderPressed="{Binding IsPressed, ElementName=PART_DropDownButton}" RenderEnabled="{TemplateBinding IsEnabled}" SnapsToDevicePixels="True"> 
               <Grid> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition Width="*"/> 
                 <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> 
                </Grid.ColumnDefinitions> 
                <TextBox x:Name="TextBox" BorderThickness="0" Background="Transparent" Cursor="Arrow" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalScrollBarVisibility="Hidden" IsReadOnly="True" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Text="{Binding Content, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" VerticalScrollBarVisibility="Hidden" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                <Grid Grid.Column="1" HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> 
                 <Path x:Name="Arrow" Data="M0,1C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1z" Fill="Black" HorizontalAlignment="Center" Margin="3,0" VerticalAlignment="Center"/> 
                </Grid> 
               </Grid> 
              </xctk:ButtonChrome> 
              <ControlTemplate.Triggers> 
               <Trigger Property="IsChecked" Value="True"> 
                <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/> 
               </Trigger> 
               <Trigger Property="IsEnabled" Value="False"> 
                <Setter Property="Fill" TargetName="Arrow" Value="#FFAFAFAF"/> 
               </Trigger> 
               <DataTrigger Binding="{Binding IsEditable, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type xctk:CheckComboBox}}}" Value="True"> 
                <Setter Property="IsReadOnly" TargetName="TextBox" Value="False"/> 
                <Setter Property="Focusable" TargetName="TextBox" Value="True"/> 
                <Setter Property="Cursor" TargetName="TextBox" Value="{x:Null}"/> 
               </DataTrigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </ToggleButton.Style> 
        </ToggleButton> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlMouseOverBorderKey, TypeInTargetAssembly={x:Type Themes:ResourceKeys}}}"/> 
     </Trigger> 
     <Trigger Property="IsKeyboardFocusWithin" Value="True"> 
      <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlSelectedBorderKey, TypeInTargetAssembly={x:Type Themes:ResourceKeys}}}"/> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

回答

0

没有为复选框没有特别的风格。您可以通过添加一个隐含的CheckBox风格的CheckComboBox这些样式:

<xctk:CheckComboBox> 
    <xctk:CheckComboBox.Resources> 
     <Style TargetType="CheckBox"> 
      <Setter Property="Background" Value="Yellow" /> 
     </Style> 
    </xctk:CheckComboBox.Resources> 
</xctk:CheckComboBox> 
+0

也做到了,谢谢! – baerlein