This is a migrated thread and some comments may be shown as answers.

Issue with RadTreeViewItemStyle when Virtualizing is "on"

0 Answers 49 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 30 Aug 2016, 05:22 AM

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)

<t:RadTreeView.Resources>
    <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>
    <Style TargetType="t:RadTreeViewItem" BasedOn="{StaticResource DefaultTreeViewItemStyle}" />
</t:RadTreeView.Resources>

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)
            continue;
 
        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

 

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Art
Top achievements
Rank 1
Share this question
or