virtualizing treeview in silverlight

梦想与她 提交于 2019-12-11 06:25:11

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/5837953/virtualizing-treeview-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!