Issue with RadTreeViewItemStyle when Virtualizing is "on"

1 posts, 0 answers
  1. Артур
    Артур avatar
    32 posts
    Member since:
    Apr 2015

    Posted 30 Aug 2016 Link to this post

    Search ViewModel change binded ItemsSource [ViewModel.Items = new ObservableCollection <DataItemViewModel> ();] and replaces it with a hierarchical result every time a user changes the query string in the TextBox.

    When Virtualizing is "on" and there is a custom RadTreeViewItemStyle (+ IsExpanded on all hierarchy items)

        <Style TargetType="t:RadTreeViewItem" x:Key="DefaultTreeViewItemStyle">
            <Setter Property="FontWeight" Value="Normal" />
            <Setter Property="FontStyle" Value="Normal" />
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
        <Style TargetType="t:RadTreeViewItem" BasedOn="{StaticResource DefaultTreeViewItemStyle}" />

    Exception: InvalidOperationException
    Message : A VirtualizingPanel is not nested in an ItemsControl. VirtualizingPanel must be nested in ItemsControl to get and show items.

    But I can solve it by using custom ItemContainerStyleSelector with

    private static Style CloneStyle(Style sourceStyle)
        if (sourceStyle == null)
            return null;
        var clonnedStyle = new Style(sourceStyle.TargetType)
            BasedOn = sourceStyle.BasedOn
        foreach (var setterBase in sourceStyle.Setters)
            var setter = setterBase as Setter;
            if (setter == null)
            clonnedStyle.Setters.Add(new Setter
                Property = setter.Property,
                Value = setter.Value
        return clonnedStyle;


    Microsoft Silverlight (64-bit) Version: 5.1.41105.0

    Windows 8.1 (64-bit)

    Internet Explorer 11.0.9600.17416

    Telerik 2016.2.503.1050


Back to Top