I have a WPF window with a TreeView that contains a checkbox at each node. I want to be able to capture the state of the checkboxes but I don’t know how. (I am trying to do this without writing much of the code in XML)
Here is what I have in the XML:
<TreeView Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="1" Height="200" HorizontalAlignment="Left" Margin="126,299,0,0" Name="TreeView1" VerticalAlignment="Top" Width="220" ItemsSource="{Binding}" DataContext="{Binding}">
</TreeView>
And in the VB Code:
Dim site As ELSite
Dim sites() As ELSite
Dim parentCheckbox = New CheckBox
Dim parentNode = New TreeViewItem
parentCheckbox.Content = "All Sites"
parentNode.Header = parentCheckbox
For Each osite In sites
Dim childNode = New TreeViewItem
Dim childCheckbox = New CheckBox
childCheckbox.Content = osite.SiteName.ToString
childNode.Header = childCheckbox
parentNode.Items.Add(childNode)
Next
TreeView1.Items.Add(parentNode)
Private Sub TreeView1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Object)) Handles TreeView1.SelectedItemChanged
'This event doesn't seem to occur when I check or uncheck a checkbox
End Sub
Thanks for the help!
1 Answer