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

Checklistbox help

Oct 26, 2012 at 7:18 PM
Edited Oct 29, 2012 at 3:58 PM


I am new to xaml wpf and mvvm.  we are using an extened checkboxlist which works well.

the problem i an having is setting the colurs for the checklistbox, by default it is whit background, all i want is to set this to another colour but have tried creating a theme file.

i have a checklistbosstyles.xaml file for the checkboxlist, but not sure how to layout the file so it does the theme, i tries <setter property="background" value="red"> but it only does the scrollbar area and not the white listbox background.

I have added the style file in the sttyles.xaml and does reference the style file.

In style.xaml

<ResourceDictionary xmlns=""
        <ResourceDictionary Source="CheckListBoxStyles.xaml"/>       
   <Style TargetType="xctk:CheckListBox" BasedOn="{StaticResource StandardUserControl}"/>   

In view.xaml

                <ColumnDefinition Width="1*"></ColumnDefinition>
                <ColumnDefinition Width="1*"></ColumnDefinition>
            <TextBlock Grid.Row="0" Grid.Column="0" Foreground="White" Text="Data Privileges" VerticalAlignment="Top" HorizontalAlignment="Left"></TextBlock>
            <xctk:CheckListBox Name="checkListBoxData" ItemsSource="{Binding Path=DataPrivileges, Mode=TwoWay}"
                                  DisplayMemberPath="PrivilegeDescription" DockPanel.Dock="Top" Margin="0,22,0,15">

            <TextBlock Grid.Row="0" Grid.Column="1" Foreground="White" Text="System Privileges" VerticalAlignment="Top" HorizontalAlignment="Left"></TextBlock>
            <xctk:CheckListBox Name="checkListBoxSystem"  ItemsSource="{Binding Path=SysPrivileges, Mode=TwoWay}"
                                  DisplayMemberPath="PrivilegeDescription" DockPanel.Dock="Top" Grid.Column="1" Margin="0,22,0,15">

In the CheckListBoxStyles.xaml

<ResourceDictionary xmlns=""                   
        <ResourceDictionary Source="/PNC.Styles;component/Resources.xaml"/>       

    <Style x:Key="StandardCheckListBox" TargetType="xctk:CheckListBox">
        <Setter Property="Background" Value="Red"/>  - doesnt work?
        <Setter Property="BorderBrush" Value="Transparent"/>       


The problem here is i dont know how to create this file for a custom control like this.  I have other style files for normal controls such as datagrid, etc which work fine.


Any help here would be great as i am running out of time.


Thanks in advance

Nov 1, 2012 at 2:25 PM

You will have to set the style on your CheckListBox. Also, to change the background color of the CheckListbox, you have to change the background color of the SelectorItems which are the listBox items. Here's a simple example :

        <local:FileNames x:Key="myList" >

        <Style x:Key="StandardSelectorItem" TargetType="xctk:SelectorItem">
            <Setter Property="Background" Value="Red"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <xctk:CheckListBox Name="checkListBoxSystem"
                               ItemsSource="{StaticResource myList}"
                               ItemContainerStyle="{StaticResource StandardSelectorItem}" />

Nov 2, 2012 at 1:36 PM

Wow, Thanks mate that did the trick, was stuck on this for so long.

Big thanks. :)