I'm trying to update my old source code to UWP referencing Microsoft.UI.Xaml.dll TreeView control to display/replicate files and folders stored in a string[].
string[] stores the complete paths to one or more files.
Example:
C:\Users\User\Documents\Test1.txt
C:\Users\User\Documents\Test2.txt
C:\Users\User\Documents\folder\Test1.txt
C:\Users\User\Documents\folder\Test2.txt
The code that I would like to update is the following:
private void PopulateTreeView(TreeView treeView, string[] paths, char pathSeparator)
{
TreeNode lastNode = null;
string subPathAgg;
long count = 0;
foreach (string path in paths)
{
subPathAgg = string.Empty;
foreach (string subPath in path.Split(pathSeparator))
{
Application.DoEvents();
subPathAgg += subPath + pathSeparator;
TreeNode[] nodes = treeView.Nodes.Find(subPathAgg, true);
if (nodes.Length == 0)
{
if (lastNode == null)
{
lastNode = treeView.Nodes.Add(subPathAgg, subPath);
}
else
{
lastNode = lastNode.Nodes.Add(subPathAgg, subPath);
}
count++;
}
else
{
lastNode = nodes[0];
}
}
lastNode = null;
}
}
Does anyone know how to update this code using Microsoft.UI.Xaml.dll TreeView control? I thought this should be easy, but I feel like I've missed something.
What I have tried:
Tried to google references on Microsoft.UI.Xaml.dll TreeView control but couldn't find any examples related to displaying files/folders from a string array.