Friday, 27 September 2013

WPF TreeViewItem Deselect Not Changing Underlying Data

WPF TreeViewItem Deselect Not Changing Underlying Data

I have a TreeView that's databound to a class with various properties, one
of which is an "IsChecked" boolean that is supposed to represent whether
the item in the tree is checked or not. Deselecting the item seems to
work, the code runs through the "Set" of the property and looks to alter
it, however when the property is referenced later, I see that the value
has not changed.
I need for the underlying class property's value to change when the tree
view item it's bound to is selected/deselected.
This is the property.
Public Property IsChecked() As System.Nullable(Of Boolean)
Get
Return isCheckedLocal
End Get
Set(value As System.Nullable(Of Boolean))
If isCheckedLocal = value Then
Return
Else
isCheckedLocal = value
RaiseEvent selectionChanged(BusGrp, Name, value)
End If
End Set
End Property
Here is the TreeView XAML:
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=BusGrps}">
<CheckBox Content="{Binding Path=Name}" IsEnabled="{Binding
Path=Enabled}" IsChecked="{Binding Path=IsChecked,
Mode=TwoWay}"></CheckBox>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Programs}">
<CheckBox Content="{Binding Path=Name}" IsEnabled="{Binding
Path=Enabled}" IsChecked="{Binding Path=IsChecked,
Mode=TwoWay}"></CheckBox>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Path=Name}"
IsEnabled="{Binding Path=Enabled}" IsChecked="{Binding
Path=IsChecked, Mode=TwoWay}"></CheckBox>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>

No comments:

Post a Comment