【发布时间】:2013-07-05 20:43:39
【问题描述】:
有没有办法将从树视图派生的自定义控件的虚拟化默认设置为 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" />
【问题讨论】:
-
只是好奇...为什么它是 Setter Property="telerik:TreeViewPanel.IsVirtualizing"?在样式中使用 VirtualizingStackPanel.IsVirtualizing="True" 不起作用吗?
-
我试过了,但给出了错误“属性'IsVirtualizing'不可附加到'ResourceDictionary'类型的元素”。上面的代码在创建自定义控件时创建的 Generic.Xaml 中。
-
你能发布你的 MyTreeViewControl 吗?
-
我已经更新了主要问题,将代码包含在两个文件中,干杯...
标签: wpf treeview virtualization