RadTreeView.ContainerFromItemRecursive returning null

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    37 posts
    Member since:
    Dec 2012

    Posted 21 Oct 2015 Link to this post

    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

     

  2. Andrew
    Andrew avatar
    37 posts
    Member since:
    Dec 2012

    Posted 21 Oct 2015 Link to this post

    Managed to achieve what I wanted by using this very useful article.

     

    http://docs.telerik.com/devtools/wpf/controls/radtreeview/how-to/howto-tri-state-mvvm.html

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top