Handle CheckBox Unchecked events : CheckBox « Windows Presentation Foundation « VB.Net

Handle CheckBox Unchecked events

Handle CheckBox Unchecked events
<Window x:Class="WpfApplication1.Window1"
    Title="WPF" Height="250" Width="300">
    <StackPanel Name="panel">
        <CheckBox Content="First CheckBox" 
                  IsChecked="True" Margin="2" Name="checkbox1" 
        <CheckBox Content="Second CheckBox" 
                  IsChecked="False" Margin="2" Name="checkbox2" 
        <Button Content="Get Selected" Margin="5" MaxWidth="100" 
                Click="Button_Click" />
        <TextBlock FontWeight="Bold" Text="Selected CheckBoxes:" />
        <ListBox Margin="5" MinHeight="2cm" Name="listbox" />
Imports System.Linq
Imports System.Windows
Imports System.Windows.Controls

Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Public Sub New()
    End Sub
    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
      For Each checkbox As CheckBox In panel.Children.OfType(Of CheckBox)().Where(Function(cb) cb.IsChecked = True)
    End Sub

    Private Sub CheckBox_Unchecked(sender As Object, e As RoutedEventArgs)
      If Not IsInitialized Then
      End If

      Dim checkbox As CheckBox = TryCast(e.OriginalSource, CheckBox)

      If checkbox IsNot Nothing Then
        MessageBox.Show(checkbox.Name & " is unchecked.", Title)
      End If
    End Sub
  End Class
End Namespace


Related examples in the same category

1.CheckBox checked event listenerCheckBox checked event listener
2.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.
3.Handle CheckBox checked eventsHandle CheckBox checked events
4.Use Linq to get checked CheckBoxUse Linq to get checked CheckBox
5.Check the CheckBox based on key pressed statesCheck the CheckBox based on key pressed states