默认情况下,有没有办法将从树视图派生的自定义控件的虚拟化设置为 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" />