在 silverlight 中虚拟化树视图

发布于 2024-11-04 04:51:44 字数 1787 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-11-11 04:51:44

你应该看看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文