在 Silverlight 中虚拟化树视图 [英] virtualizing treeview in silverlight

查看:32
本文介绍了在 Silverlight 中虚拟化树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Silverlight 工具包树视图来显示数据集.它有 1000 个元素,有些子元素也有多达 500 个子元素.加载数据并在树视图中显示它需要将近一分钟.树视图有虚拟化吗?如果是这样,请有人给我指出示例或代码片段吗?

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?

以下是 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类

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

推荐答案

你应该看看 Bea Costa 关于这个问题的文章.在此处查看她的博客.从 3.5 开始,silverlight 为树视图选择了虚拟化.可以提高性能的一件事是按需加载子节点.她在她的文章中介绍了这一点.

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.

基本上,它归结为:您应该只加载到 UI 中,您需要加载.

basically, it boils down to this: you should only load into the UI, what you need to.

这篇关于在 Silverlight 中虚拟化树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆