I got roughly about 127K of TreeViewItems and I need to make UI Virtualization working.
My XAML:
<TreeView ScrollViewer.CanContentScroll="True" ItemsSource="{Binding}" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" Visibility="Hidden" Name="treeView" Margin="10,10,10,0" VerticalAlignment="Top" Grid.Column="0" SelectedItemChanged="treeView_SelectedItemChanged" BorderThickness="0"/>
And My C#:
treeView.Visibility = Visibility.Visible;
articleIndexer = OpDb.Articles;
int count = articleIndexer.GetCount();
//if (count > 1000)
// count = 1000;
IEnumerable<TBase3.Article> articles = articleIndexer.GetArticles(0, count);
List<TreeViewItem> items = new List<TreeViewItem>();
foreach (var article in articles)
{
TreeViewItem item1 = new TreeViewItem();
item1.Header = article.Name;
item1.Tag = new DbInfo() { RelatedId = article.BlockIndex, DbId = article.Database.Id, IsArticle = true };
items.Add(item1);
//treeView.Items.Add(items);
}
Items = items;
treeView.DataContext = Items;
articles count is over 127K and after forearch loop is done it does view my TreeViewItems. But my GUI goes TILT and I need to end process to shutdown application. So I'm guessing my Virtualization is not working because GUI is not responding. Items is IList
TreeViewItem
manually. Simply bind the collection with TreeView and treeView internally creates TreeViewItem for you. Since you already have created containers (TreeVieItem) how will virtualization get a chance to play its part? - Rohit Vats