I had tried that approach to no avail. However, I did figure out order of events and was able to add code to the code behind to get it to work. Hopefully this will help someone else out as i saw this question posted several times without concrete solution.
I changed my bindings to the CheckState property (as opposed to isChecked property). Final XAML below:
<
UserControl.Resources
>
<!-- Page Converters -->
<
converters:BooleanToToggleStateConverter
x:Key
=
"Bool2ToggleConverter"
/>
<
telerik:ContainerBindingCollection
x:Key
=
"TreeBindings"
>
<
telerik:ContainerBinding
PropertyName
=
"CheckState"
Binding
=
"{Binding IsChecked, Mode=TwoWay, Converter={StaticResource Bool2ToggleConverter}}"
/>
<
telerik:ContainerBinding
PropertyName
=
"IsExpanded"
Binding
=
"{Binding IsExpanded, Mode=TwoWay}"
/>
</
telerik:ContainerBindingCollection
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"TreeItemTemplate"
ItemsSource
=
"{Binding Children}"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource TreeBindings}"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding DisplayName}"
/>
</
StackPanel
>
</
telerik:HierarchicalDataTemplate
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Margin
=
"10"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadTreeView
SelectionMode
=
"Single"
Grid.Row
=
"1"
ItemTemplate
=
"{StaticResource TreeItemTemplate}"
ItemsSource
=
"{Binding ProcessTreeRoot}"
ItemPrepared
=
"processSelectTree_ItemPrepared"
IsLoadOnDemandEnabled
=
"True"
LoadOnDemand
=
"processSelectTree_LoadOnDemand"
ItemsOptionListType
=
"CheckList"
IsOptionElementsEnabled
=
"True"
PreviewUnchecked
=
"processSelectTree_PreviewUnchecked"
IsExpandOnSingleClickEnabled
=
"True"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource TreeBindings}"
Checked
=
"processSelectTree_Checked"
Unchecked
=
"processSelectTree_Checked"
Margin
=
"0"
x:Name
=
"processSelectTree"
IsTriStateMode
=
"True"
/>
</
Grid
>
</
UserControl
>
The magic happens in my code behind. I set a flag to detect when a node is being expanded and not yet loaded. Since this event happens before the unwanted Unchecked event, I am able to use the PreviewUnchecked event to see if Im in this unwanted state. If I am, I simply throw that event away:
{
private
bool
bExpandingCheckedUnloadedItem_TelerikHack =
false
;
public
DocumentAssignmentByProcess()
{
InitializeComponent();
}
private
void
processSelectTree_LoadOnDemand(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
RadTreeViewItem treeitem = e.OriginalSource
as
RadTreeViewItem;
(DataContext
as
DocumentAssignmentByProcessViewModel).LoadChildrenOnDemandCommand.Execute(treeitem.Item
as
PlantConfigTreeItem);
// telerik tree hack. apparently if a node is checked (and not yet loaded), it will get unchecked when expanded
if
(treeitem.CheckState == System.Windows.Automation.ToggleState.On)
{
treeitem.IsChecked =
true
;
bExpandingCheckedUnloadedItem_TelerikHack =
true
;
}
}
private
void
processSelectTree_ItemPrepared(
object
sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e)
{
RadTreeViewItem treeitem = (RadTreeViewItem)e.PreparedItem;
treeitem.IsLoadOnDemandEnabled = (treeitem.Item
as
PlantConfigTreeItem).HasChildren;
}
private
void
processSelectTree_PreviewUnchecked(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
// more of the hack.. after the tree node is expanded, the tree control for some reason unselects the parent node
// this code checks for situatio where node was originally checked (indicated by bExpandingCheckedUnloadedItem)
// and will check it and cancel uncheck event
if
(bExpandingCheckedUnloadedItem_TelerikHack)
{
bExpandingCheckedUnloadedItem_TelerikHack =
false
;
e.Handled =
true
;
RadTreeViewItem treeitem = e.OriginalSource
as
RadTreeViewItem;
treeitem.IsSelected =
true
;
}
}