This project has moved. For the latest updates, please go here.

CheckListBox HighlightBrushKey

May 9, 2012 at 3:01 PM

It appears that CheckListBox ignores setting the selected item background color use HighLightBrushKey.

Is there a different Key that we should be setting?

The following code doesn't work as expected:

<wpf:CheckListBox.Resources>
       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                               Color="White" />
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                               Color="LightGray" />
</wpf:CheckListBox.Resources>

Coordinator
May 11, 2012 at 4:33 PM

Thank you to have signalled the issue.  I have created the following issue to solve the problem.

 

In the meantime, you may use the following style to patch the CheckListBox.  The same fix could be applied for the CheckComboBox.

<Style TargetType="{x:Type xctk:SelectorItem}">
   <Setter Property="Background"
           Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
            
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type xctk:SelectorItem}">
            <Border x:Name="_background"
                     Background="{TemplateBinding Background}"
                     BorderBrush="{TemplateBinding BorderBrush}"
                     BorderThickness="{TemplateBinding BorderThickness}">
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <CheckBox Name="PART_CheckBox" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" Focusable="False"  Margin="3,1,5,1" />
                  <Border Grid.Column="1">
                     <ContentPresenter Margin="2" ContentSource="Content" />
                  </Border>
               </Grid>
            </Border>
            <ControlTemplate.Triggers>
               <Trigger Property="IsMouseOver" Value="True">
                  <Setter TargetName="_background" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                  <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
               </Trigger>
               <Trigger Property="IsSelected" Value="True">
                  <Setter TargetName="_background" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                  <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
               </Trigger>
            </ControlTemplate.Triggers>
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>
May 14, 2012 at 4:52 PM

This didt not work with ItemsSource Binding.

System.InvalidOperationException ist aufgetreten.
  Message=Items collection must be empty before using ItemsSource.
  Source=PresentationFramework
  StackTrace:
       at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)
  InnerException:

May 17, 2012 at 4:52 PM

That works. Thanks so much.