I have a RadTreeView that I am expanding by applying a style.
<
Style
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
>
<
EventSetter
Event
=
"Selected"
Handler
=
"TreeViewItem_Selected"
/>
<
Setter
Property
=
"IsExpanded"
Value
=
"True"
></
Setter
>
</
Style
>
I am trying to display checkboxes next to items that meet a certain condition. To do this I am trying to hide the checkboxes on those elements that do not meet the condition.
I am hooking into the loaded event of my RadTreeView and trying to iterate down through the items, get the item container and hide the checkbox if necessary.
The problem I am having is that ContainerFromItemRecursive is returning null for any item that is not at the root level.
Here's my code.
private
void
FrameworkElement_OnLoaded(
object
sender, RoutedEventArgs e)
{
RadTreeView rtv = sender
as
RadTreeView;
foreach
(IMeasurementTreeBase item
in
rtv.Items)
{
SetCheckBoxVisibilityRecursive(item, rtv);
}
}
}
public
void
SetCheckBoxVisibilityRecursive(IMeasurementTreeBase item, RadTreeView rtv)
{
if
(!item.HasMeasurements())
{
RadTreeViewItem treeItem = rtv.ContainerFromItemRecursive(item);
if
(treeItem !=
null
)
{
var children = treeItem.ChildrenOfType<CheckBox>().ToList();
children[0].Visibility = Visibility.Collapsed;
}
foreach
(IMeasurementTreeBase subItem
in
item.Children)
{
SetCheckBoxVisibilityRecursive(subItem, rtv);
}
}
}
Thanks