virtualizing treeview in silverlight
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="{Bindin开发者_运维问答g 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));
}
}
}
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.
精彩评论