默认情况下,在自定义控件中将树视图虚拟化设置为true

时间:2013-07-08 13:31:12

标签: wpf treeview virtualization

默认情况下,有没有办法将从树视图派生的自定义控件的虚拟化设置为true?例如,我有一个从RadTreeView派生的自定义控件:

public class MyTreeViewControl : RadTreeView
{
    static MyTreeViewControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MyTreeViewControl), new FrameworkPropertyMetadata(typeof(MyTreeViewControl)));
    }
}

和包含以下内容的Generic.Xaml文件:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:userControls="clr-namespace:HDC.Solus.WPF.UserControls"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:classes="clr-namespace:HDC.Solus.WPF.Classes">

<HierarchicalDataTemplate DataType="{x:Type classes:MyTreeViewItem}" ItemsSource="{Binding Children}">
    <StackPanel Orientation="Horizontal">
        <Image Height="16" Width="16" Source="{Binding IconUri}" />
        <TextBlock Text="{Binding Text}" />
    </StackPanel>
</HierarchicalDataTemplate>

<Style TargetType="{x:Type userControls:MyTreeViewControl}" BasedOn="{StaticResource {x:Type telerik:RadTreeView}}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type userControls:MyTreeViewControl}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="telerik:TreeViewPanel.IsVirtualizing" Value="True"/>
</Style>

但是,默认情况下不启用虚拟化,启用虚拟化的唯一方法是在创建虚拟化时将其直接设置在控件上,例如:

<userControls:MyTreeViewControl IsVirtualizing="True" />

1 个答案:

答案 0 :(得分:0)

我没有太多地使用过这个...但是会替换Treeviewpanel或某个模板而你选择的其中一个不起作用?如果你不能在xaml中设置它。

如果要覆盖控件的默认元数据,可以在构造函数中执行类似的操作。不确定它是否会有所帮助

TreeView.ItemsPanelProperty.OverrideMetadata(typeof(MyTreeViewControl), new PropertyMetadata(myNewItemsPanel));

这就是你通常如何改变继承对象的依赖属性。

您可能还想在自定义控件中创建“IsVirtualizing依赖项属性,然后在”OnApplyTemplate“中将属性绑定到telerik:TreeViewPanel.IsVirtualizing属性。或者在Telerik中绑定:XAML中的TreeViewPanel.IsVirtualizing属性created is Virtualizing依赖属性。

希望你能解决它:)