This project has moved and is read-only. For the latest updates, please go here.

CheckListBox keyboard interaction

May 13, 2012 at 11:54 AM

Hello,

When clicking with the mouse, the checked item is highlighted and as the mouse moves up and down the list the highlight follows the mouse.

If I check an item in the list with the mouse and then react to the up and down arrow keys to change the selected item, the highlight does not move with the newly selected items.

May 14, 2012 at 9:50 AM
Edited May 14, 2012 at 9:53 AM

I happened upon this thread - CheckListBox HighlightBrushKey [discussion:355090]: http://wpftoolkit.codeplex.com/discussions/355090. Applying the style patch referenced fixed the problem. I copied in the style fix for reference purposes. The IsSelected trigger fixes the issue.

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