Articles in this section
Category / Section

How to get the tapped node full path in Xamarin.Forms TreeView?

1 min read

You can get the full path of TreeViewNode when tapping the TreeviewNode in Xamarin.Forms Xamarin.Forms TreeView.

C#

Get the tapped TreeViewNode path value in the TapCommand.

private Command<Object> tappedCommand;
 
public Command<object> TappedCommand
{
    get { return tappedCommand; }
    set { tappedCommand = value; }
}
 
public FileManagerViewModel()
{
    TappedCommand = new Command<object>(TappedCommandMethod);
}
 
private void TappedCommandMethod(object obj)
{
   string nodepath = GetNodePath(obj as Syncfusion.TreeView.Engine.TreeViewNode);
   App.Current.MainPage.DisplayAlert("Path ", nodepath, "Ok");
}

C#

Collect the parent node of Selected TreeViewNode in GetNodePath method

public string GetNodePath(Syncfusion.TreeView.Engine.TreeViewNode node)
{
    string fullpath = "";
    string path = "";
    while (node != null)
    {
       path = @"\" + (node.Content as FileManager).ItemName;
       if (node.ParentNode != null)
       {
           node = node.ParentNode;
       }
       else
       {
           node = null;
       }
       fullpath = path + fullpath;
    }
    return fullpath;
}

View sample on GitHub

How to get the full path of a tapped node in Xamarin.Forms TreeView (SfTreeView)

Take a moment to pursue the documentation, where you can find more about SfTreeView with code examples.


Conclusion

I hope you enjoyed learning about how to get the tapped node full path in Xamarin.Forms TreeView.

You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms ListView documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied