I bind XML file to WPF TreView using this code:
XmlDocument XMLdoc = new XmlDocument();
try
{
XMLdoc.Load(file);
XmlDataProvider provider = new XmlDataProvider();
provider.Document = XMLdoc;
Binding binding = new Binding();
binding.Source = provider;
binding.XPath = "child::node()";
xmlTree.SetBinding(TreeView.ItemsSourceProperty, binding);
}
catch (XmlException)
{
MessageBox.Show("The XML file is invalid");
return;
}
I cannot say that XML is too big but it takes a lot of time more than 1 min to bind and show XML data under WPF TreeView.
My question is: Are there any points that we can optimize?
(NOTE: The final idea is to show XML under WPF App.)
I had the same problem and solved it by setting the TreeView property “VirtualizingStackPanel.IsVirtualizing” to “true”.