Option 1Option 2Option 3
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ClassicControls
{
public partial class CheckBoxList : System.Windows.Window
{
public CheckBoxList()
{
InitializeComponent();
}
private void lst_SelectionChanged(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is CheckBox)
{
lst.SelectedItem = e.OriginalSource;
}
if (lst.SelectedItem == null) return;
Console.WriteLine(lst.SelectedIndex);
Console.WriteLine(((CheckBox)lst.SelectedItem).IsChecked);
}
private void cmd_CheckAllItems(object sender, RoutedEventArgs e)
{
foreach (CheckBox item in lst.Items)
{
if (item.IsChecked == true)
{
Console.WriteLine((item.Content + " is checked."));
}
}
}
}
}