There is an angular example of how to return the fullpath for a node. I need to do this with Xamarin.Forms. I have tried to convert angular to c# but I failed miserably. I cannot make it work. Can someone point me to a solution that shows how to return the path of a node/element within a node?
Brian
|
private void SfTreeView_ItemTapped(object sender, Syncfusion.XForms.TreeView.ItemTappedEventArgs e)
{
string nodepath = viewModels.GetNodePath(e.Node);
App.Current.MainPage.DisplayAlert("Path ", nodepath, "Ok");
}
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;
} |
This is beautiful. Thank you. Now I need to integrate lazy loading to pull data from a REST API.
Sorry to trouble again. I used the example above. I am using the NodeExpanding event in the behaviors code. When I try to add said data it never populates in the node. What on earth am I doing wrong? I've added the event code here. the code below is located in SFTVBehaviors.cs
private void sfTreeview_NodeExpanding(object sender, NodeExpandingCollapsingEventArgs e)
{
var nodeImageInfo = new ObservableCollection<FileManager>();
Assembly assembly = typeof(ItemsPage).GetTypeInfo().Assembly;
var tvnc = new ObservableCollection<TreeViewNode>();
var tvn = new TreeViewNode();
var node = e.Node;
node.ChildNodes.Clear();
var path = GetNodePath(node);
var ph = new FileManager() { ItemName = "Placeholder", ImageIcon = ImageSource.FromResource("asbuiltgui_mobile.Icons.treeview_folder.png", assembly) };
var placeholder = new ObservableCollection<FileManager>();
placeholder.Add(ph);
var results = Utils.UtilityCalls.lambdaGetFolders(path);
var folders = JsonConvert.DeserializeObject<List<string>>(results);
foreach (string Folder in folders)
{
tvn.Content = new FileManager() { ItemName = Folder, ImageIcon = ImageSource.FromResource("asbuiltgui_mobile.Icons.treeview_folder.png", assembly), SubFiles = placeholder };
tvnc.Add(tvn);
}
node.PopulateChildNodes(tvnc);
if (node.ChildNodes.Count() > 0)
//Expand the node after child items are added.
node.IsExpanded = true;
}
Sorry you can ignore the previous request. I was able to fix it with lazy loading. Now the last issue Im having is I cannot get vertical or horizontal scrolling to work. How do I diagnose that and fix it?