在 silverlight 中虚拟化树视图
我正在使用 silverlight 工具包树视图来显示数据集。它有 1000 个元素,一些子元素也有多达 500 个子元素。加载数据并在树视图中显示它需要大约一分钟的时间。树视图有虚拟化吗?如果确实如此,有人可以给我指一个示例或代码片段吗?
以下是 XAML
<controls:TreeView Grid.Column="0" VerticalAlignment="Stretch"
ItemsSource="{Binding People}" >
<controls:TreeView.ItemTemplate>
<common:HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="90*"/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding TwoState}" Grid.Column="0"/>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</StackPanel>
</common:HierarchicalDataTemplate>
</controls:TreeView.ItemTemplate>
</controls:TreeView>
以下是我使用的 person 类
public class Person:INotifyPropertyChanged
{
public string Name { get; set; }
public int Age { get; set; }
public bool TwoState { get; set; }
public ObservableCollection<Person> Children { get; set; }
public Person()
{
TwoState = false;
Children = new ObservableCollection<Person>();
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
I am using silverlight toolkit treeview to show set of data. It has 1000 elements and some of the child elements have as much as 500 child elements as well. It takes almost a minute to load the data and show it in treeview. Does the tree view have virtualization? If it does, could some one point me to a sample or code snippet please?
Following is the XAML
<controls:TreeView Grid.Column="0" VerticalAlignment="Stretch"
ItemsSource="{Binding People}" >
<controls:TreeView.ItemTemplate>
<common:HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="90*"/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding TwoState}" Grid.Column="0"/>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</StackPanel>
</common:HierarchicalDataTemplate>
</controls:TreeView.ItemTemplate>
</controls:TreeView>
Following is the person class I use
public class Person:INotifyPropertyChanged
{
public string Name { get; set; }
public int Age { get; set; }
public bool TwoState { get; set; }
public ObservableCollection<Person> Children { get; set; }
public Person()
{
TwoState = false;
Children = new ObservableCollection<Person>();
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该看看 Bea Costa 关于此事的文章。
请在此处查看她的博客。从 3.5 开始,silverlight 为树视图选择了虚拟化。提高性能的方法之一是按需加载子节点。她在她的文章中介绍了这一点。
基本上,它可以归结为:您应该只加载您需要的内容到 UI 中。
you should take a look at Bea Costa's article on the matter.
check out her blog here. as of 3.5, silverlight has opt-in virtualization for the tree view. one of the things that will speed up your performance is loading child nodes on demand. she covers this in her article.
basically, it boils down to this: you should only load into the UI, what you need to.