How To Create WPF Multiple Column CheckedListBox Using XAML

Working with WPF is lot of fun. We can configure every element of WPF controls to render them as we want. But identifying the configuration elements that need to be modified is the toughest task. Having many years of WinForms development experience, did not help me much to easily adopt to WPF programming. WPF is a brand new framework and it’s entirely different to WinForms.


After spending couple of days time with WPF, I learned the basic of Data Templates and configured WPF ListBox control to render it as a CheckedListBox control. Here is the XAML code to render a WPF ListBox control as a Checked ListBox control



<ListBox Name="CategoryListBox"
         ItemsSource="{Binding Path=RefValues,
            <WrapPanel />
        <DataTemplate >
            <StackPanel Orientation="Horizontal"
                        MinWidth="150" MaxWidth="150"
                        Margin="0,5, 0, 5" >
                            RelativeSource={RelativeSource FindAncestor,
                            AncestorType={x:Type ListBoxItem} },
                            Path=IsSelected, Mode=TwoWay}" />
                            RelativeSource={RelativeSource TemplatedParent},
                    Margin="5,0, 0, 0" />

3 thoughts on “How To Create WPF Multiple Column CheckedListBox Using XAML”

  1. Hi:
    I also got this error when using someones elses UserControl:

    “ancestor type must be specified for relativesource in findancestor mode”

    I found that the problem was in my code-behind C# file
    where I was missing some ‘using’ lines.

  2. Shashi kant sinha


    This code is giving an error message in XAML as below: –

    “ancestor type must be specified for relativesource in findancestor mode”

    I did not do any changes in code, simply copied and paste within the windows grid..



  3. Pingback: Brainsick Patterns — No Code Relation » Article » Where is the CheckedListBox in a Smart Device project?

Leave a Comment

Your email address will not be published. Required fields are marked *