Im trying to hard to get a treeview that has loading on demand enabled with checkboxes. I run into issues if I have a parent node checked and then try to expand it (which triggers a load on demand operation). If the parent was checked, I build the children and make sure they have the checked property as well. When all is complete, the treeview successfully loads the children, the children are all checked as expected, but the parent node (that was expanded) gets unchecked! WHY?!
<
UserControl.Resources
>
<
telerik:ContainerBindingCollection
x:Key
=
"TreeBindings"
>
<
telerik:ContainerBinding
PropertyName
=
"IsChecked"
Binding
=
"{Binding IsChecked, Mode=TwoWay}"
/>
</
telerik:ContainerBindingCollection
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"TreeItemTemplate"
ItemsSource
=
"{Binding Children}"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource TreeBindings}"
>
<
TextBlock
Text
=
"{Binding DisplayName}"
/>
</
telerik:HierarchicalDataTemplate
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Margin
=
"10"
>
<
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"
IsExpandOnSingleClickEnabled
=
"False"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource TreeBindings}"
Margin
=
"10"
x:Name
=
"processSelectTree"
IsTriStateMode
=
"True"
>
</
telerik:RadTreeView
>
</
Grid
>
My relavant code behind :
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);
}
private
void
processSelectTree_ItemPrepared(
object
sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e)
{
RadTreeViewItem treeitem = (RadTreeViewItem)e.PreparedItem;
treeitem.IsLoadOnDemandEnabled = (treeitem.Item
as
PlantConfigTreeItem).HasChildren;
}
My View Model related code (command code triggered on load demand)
protected
void
LoadChildrenOnDemand(PlantConfigTreeItem objTreeItem)
{
if
(objTreeItem
is
LineTreeItem)
{
// string userClockNum = (HandbookMode == enHandbookMode.ALL) ? "" : ECAPApplicationState.Instance.LoggedInAssociate.ClockNumber;
prodContext.Load(prodContext.GetPositionsQuery(
""
,
ECAPApplicationState.Instance.CurrentDivisionPlantConfigId,
objTreeItem.Id),
io =>
{
ObservableCollection<PlantConfigTreeItem> positionList =
new
ObservableCollection<PlantConfigTreeItem>();
foreach
(Position pl
in
io.Entities )
positionList.Add(
new
PositionTreeItem { Id = pl.Id, DisplayName = pl.PositionTitle, HasChildren =
true
, IsChecked = objTreeItem.IsChecked });
AddRange( objTreeItem.Children, positionList);
},
null
);
}
else
if
(objTreeItem
is
PositionTreeItem)
{
// string userClockNum = (HandbookMode == enHandbookMode.ALL) ? "" : ECAPApplicationState.Instance.LoggedInAssociate.ClockNumber;
prodContext.Load(prodContext.GetAllProcessQuery(
""
,
ECAPApplicationState.Instance.CurrentDivisionPlantConfigId,
objTreeItem.Id),
io =>
{
ObservableCollection<PlantConfigTreeItem> positionList =
new
ObservableCollection<PlantConfigTreeItem>();
foreach
(Process pl
in
io.Entities)
positionList.Add(
new
ProcessTreeItem { Id = pl.Id, DisplayName = pl.Name, HasChildren =
false
, IsChecked = objTreeItem.IsChecked });
AddRange(objTreeItem.Children, positionList);
},
null
);
}
}