CheckBox List : CheckBox « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Windows Presentation Foundation » CheckBoxScreenshots 
CheckBox List
CheckBox List
  

<Window x:Class="ClassicControls.CheckBoxList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CheckBoxList" Height="300" Width="300">
  <Grid Margin="10">
    <Grid.RowDefinitions>
      <RowDefinition Height="*"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    
    <ListBox Name="lst" SelectionChanged="lst_SelectionChanged" CheckBox.Click="lst_SelectionChanged" >
      <CheckBox Margin="3">Option 1</CheckBox>
      <CheckBox Margin="3">Option 2</CheckBox>
      <CheckBox Margin="3">Option 3</CheckBox>
    </ListBox>
    <StackPanel Grid.Row="1" Margin="0,10,0,0">
      <Button Margin="0,10,0,0" Click="cmd_CheckAllItems">Examine All Items</Button>
    </StackPanel>
  </Grid>
</Window>
//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 == nullreturn;
            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."));

                }
            }
        }
    }
}

   
    
  
Related examples in the same category
1.Three-State CheckBoxThree-State CheckBox
2.A CheckBox with a skew transformationA CheckBox with a skew transformation
3.Add CheckBox to StackPanelAdd CheckBox to StackPanel
4.Customized CheckBoxCustomized CheckBox
5.CheckBox StyleCheckBox Style
6.CheckBox checked event listenerCheckBox checked event listener
7.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.
8.Handle CheckBox Unchecked eventsHandle CheckBox Unchecked events
9.Handle CheckBox checked events
10.Use Linq to get checked CheckBoxUse Linq to get checked CheckBox
11.Check the CheckBox based on key pressed statesCheck the CheckBox based on key pressed states
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.