Click here to Skip to main content
11,804,008 members (81,273 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 C# WPF wpftoolkit
i want checkboxlist in Wpf
using xaml i got the checkboxlist in design but i don't know how to use this in code this is my xaml code
<ListBox x:Name="listExtraSkills" ItemsSource="{Binding CheckList}" Grid.Column="1" Grid.Row="6" Height="50" >
                   <CheckBox Name="chkitems" Content="{Binding TheText}" IsChecked="{Binding IsSelected }"  > </CheckBox>
Posted 20-Jun-12 0:08am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Here's a working example, based on your XAML:

First of all, the code-behind:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Documents;
namespace WpfApplicationCheckBoxList
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window, INotifyPropertyChanged
        #region Instance Variables
        List<checklistitem> checkList;
        #endregion /Instance Variables

        #region INotifyPropertyChanged
        //Add this bit of code to all your code behinds
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        #endregion /INotifyPropertyChanged

        public Window1()
            CheckList = GenerateTestData();
        //Property to bind to
        public List<checklistitem> CheckList
            get { return checkList; }
            set { checkList = value; this.OnPropertyChanged(new PropertyChangedEventArgs("CheckList")); }
        //Test data helper
        List<checklistitem> GenerateTestData()
            List<checklistitem> checkListItems = new List<checklistitem>();
            checkListItems.Add(new CheckListItem { TheText = "My Text Here 1", IsSelected = false });
            checkListItems.Add(new CheckListItem { TheText = "My Text Here 2", IsSelected = true });
            checkListItems.Add(new CheckListItem { TheText = "My Text Here 3", IsSelected = false });
            return checkListItems;

Remember to set the DataContext in your XAML:
<window x:class="WpfApplicationCheckBoxList.Window1" xmlns:x="#unknown">
    DataContext="{Binding RelativeSource={RelativeSource Self}}">

And finally the data object you're binding to the list:
public class CheckListItem
    public string TheText { get; set; }
    public bool IsSelected { get; set; }
Sravanthid28 at 20-Jun-12 7:06am
if we want dynamically check the check box and respected checkedbox content store into the database?
can you please tell code for this
AdamDavidHill at 20-Jun-12 7:14am
To manipulate the values you'd write something like: CheckList[2].IsSelected = true; - i.e. you're manipulating the values of the CheckList property. To add a new check box you'd use CheckList.Add(new CheckListItem{... etc. Whether or not you store this in a database or not is a separate question and should probably be asked in another thread. Hope that helps. Please mark as the answer if this solves the question of how to use that XAML with code behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 CPallini 310
2 Sergey Alexandrovich Kryukov 234
3 CHill60 230
4 Suvendu Shekhar Giri 200
0 OriginalGriff 3,140
1 Maciej Los 1,910
2 KrunalRohit 1,907
3 CPallini 1,845
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 20 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100