I am using the checkboxes in a RadTreeView. The treeview items are bound to my own heirarchical type called TreeNode. When an item is checked how do I determine which TreeNode object was checked?
Currently I am using a command to handle the IsChecked event of the control. I am passing the event arguments to the command. I can get access to all the checked items in the tree as TreeNodes, but am at a loss as to which one was actually last checked.
<telerik:RadTreeView x:Name="TreePermissions"
DockPanel.Dock="Top"
MinHeight="50"
BorderBrush="Black"
BorderThickness="1"
Margin="5,0,5,0"
IsOptionElementsEnabled="True"
ItemsSource="{Binding UserPermissions}"
ItemPrepared="TreePermissions_ItemPrepared">
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding Command="{Binding PermissionCheckedCommand}" EventName="Checked"
PassEventArgsToCommand="True" />
</telerik:EventToCommandBehavior.EventBindings>
<telerik:RadTreeView.ItemContainerStyle>
<Style TargetType="{x:Type telerik:RadTreeViewItem}">
<Setter Property="IsExpanded" Value="True"/>
<Setter Property="IsChecked" Value="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled, UpdateSourceTrigger=PropertyChanged}"/>
</Style>
</telerik:RadTreeView.ItemContainerStyle>
</telerik:RadTreeView>
private void OnPermissionChecked(object obj)
{
var args = obj as Telerik.Windows.Controls.RadTreeViewCheckEventArgs;
Telerik.Windows.Controls.RadTreeViewItem item = args.OriginalSource as Telerik.Windows.Controls.RadTreeViewItem;
// TreeNode node = item as TreeNode; // This does not work, cannot cast/convert for some reason
Telerik.Windows.Controls.RadTreeView source = args.Source as Telerik.Windows.Controls.RadTreeView;
if (source != null)
{
List<TreeNode> temp = source.CheckedItems.Cast<TreeNode>().ToList();
}
}