First create a CheckBoxList using ListBox with DataTemplate as follows in XAML.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CheckBoxLsit" Height="350" Width="525">
<Grid>
<StackPanel Width="250" Height="80">
<ListBox Name="listBoxZone" ItemsSource="{Binding TheList}"
Height="115" Background="Azure">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Name="CheckBoxZone" Content="{Binding TheText}
Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked"
Margin="0,5,0,0"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<TextBox Name="ZoneText" Width="160" Height="20" Margin="-80,140,0,0" Background="Bisque" />
<TextBox Name="ZoneValue" Width="160" Height="20" Margin="-80,190,0,0" Background="Bisque" />
</Grid>
</Window>
Binding data to CheckBoxList in .XAML.Cs
Using System.Collections.ObjectModel;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<BoolStringClass> TheList {get; set ;}
public MainWindow()
{
InitializeComponent();
CreateCheckBoxList();
}
public class BoolStringClass
{
public string TheText { get; set; }
public int TheValue { get; set; }
}
public void CreateCheckBoxList()
{
TheList = new ObservableCollection<BoolStringClass>();
TheList.Add(new BoolStringClass { TheText = "EAST" ,TheValue =1});
TheList.Add(new BoolStringClass { TheText ="WEST",TheValue =2});
TheList.Add(new BoolStringClass { TheText ="NORTH", TheValue=3});
TheList.Add(new BoolStringClass {TheText ="SOUTH", TheValue =4});
this.DataContext =this;
}
Get the Text and value of Checked CheckBoxList
Write the code below in the checkBox Checked Event.
private void CheckBoxZone_Checked(object sender, RoutedEventArgs e)
{
CheckBox chkZone = (CheckBox)sender;
ZoneText.Text ="Selected Zone Name= "+ chkZone.Content.ToString();
ZoneValue.Text = "Selected Zone Value= " + chkZone.Tag.ToString();
}

Thanks for Reading my article!

Tzadik VanderhoofPosted Jun 2, 2017, 6:35 PM
You are missing a double-quote after Content="{Binding TheText}
shankar kumarPosted Nov 16, 2016, 7:31 AM
How to save checked listbox data using wpf mvvm ??
Shajahan PothuvacholaPosted Feb 18, 2015, 7:13 AM
how can i select all item checked when select one item
Abhishek joshiPosted Jul 31, 2012, 6:03 AM
Orignal source : http://social.msdn.microsoft.com/Forums/eu/wpf/thread/a355a085-2650-45b6-a75b-b6a298e3f20d
rolando cruzPosted Mar 23, 2011, 4:19 PM
Nice demo appreciate it. What about if you are using the M-V-VM pattern. I understand that you can't have code-behind and everything is declarative. I have a similar problem in my project where I have to use a winforms checkboxlist using interop but I don't know how to data bind it to my ViewModel. Thanks, Roland