0
Answer

Tree view in Wpf(xaml)

Nima naqipoor

Nima naqipoor

14y
4k
1
I have a problem here ;
I've create a treeview in c# like this code ,but
How can I do this in wpf (xaml); ?Confused 

public void PopulateTreeView(  string dirValue, TreeNode parentNode )
{
/* dirValue = inputTextBox.Text
parentNode = directoryTreeView.Nodes[0] ..
*
directoryTreeView is a Treeview
*/


// array stores all subdirectories in the directory
string[] directoryArray = Directory.GetDirectories( dirValue);

try {
// subdirectories are present
if ( directoryArray.Length != 0 )
{
// create new TreeNode,

foreach ( string directory in directoryArray )
{
// substringDirectory is a string defined in generall
substringDirectory = Path.GetFileNameWithoutExtension(directory );


// current directory
TreeNode myNode = new TreeNode( substringDirectory );

// add current directory node to parent node
parentNode.Nodes.Add( myNode );

// recursive populate
PopulateTreeView( directory, myNode );
}
}
}


catch ( UnauthorizedAccessException )
{
parentNode.Nodes.Add( "Access denied !" );
}
}
please explain clearly or post a snippet code (cause I'm new in xaml). Tanx
I've posted this question here but it doesn't help me.