Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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" xmlns:x="#unknown"> <listbox.itemtemplate> <datatemplate>
<checkbox name="chkitems" content="{Binding TheText}" ischecked="{Binding IsSelected }">

Posted
Comments
Sandeep Mewara 20-Jun-12 7:33am    
Why repost? You already have been shared an article on how to use it?

1 solution

Hi.
First of all create and bind entity to your UI.
Let assume that you create model like this:
C#
public class MyModel
{
public bool IsChecked{get;set;}
public string Name{get;set;}
}



Define for your listBox template for item:

HTML
<listbox x:name="lb1" xmlns:x="#unknown">
         ScrollViewer.VerticalScrollBarVisibility="Visible"> 
    <listbox.itemtemplate> 
      <datatemplate> 
        <stackpanel orientation="Horizontal"> 
          <checkbox ischecked="{Binding IsChecked, Mode=TwoWay}" /> 
          <textblock text="{Binding Name}" /> 
        </stackpanel> 
      </datatemplate> 
    </listbox.itemtemplate> 
</listbox>



Tanh in your code just bind List<mymodel> to listbox:

C#
lb1.ItemSource=list; //where list is reference to your list of MyModel.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900