Skip to content

Commit eb24b6f

Browse files
Merge pull request #1 from Santhosh-SF4792/main
Update the README.md file
2 parents 8a7cc51 + 7004159 commit eb24b6f

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
**[View document in Syncfusion Xamarin Knowledge base](https://www.syncfusion.com/kb/12488/how-to-do-conditional-navigation-in-xamarin-forms-treeview-sftreeview)**
1+
# conditional-navigation-treeview-xamarin
2+
This repository demonstrates how to implement conditional navigation in a Syncfusion Xamarin.Forms TreeView. The sample shows how to navigate to different pages or perform specific actions based on which node the user selects in the TreeView. By applying conditions in the selection changed event or command, you can control navigation flow, restrict access, or trigger custom logic dynamically according to your application's requirements.
3+
4+
## Sample
5+
6+
### XAML
7+
8+
Bind the SfTreeView.TapCommand to navigate to another page. By default, the TreeViewNode is the command parameter for the TapCommand.
9+
10+
```xaml
11+
<syncfusion:SfTreeView x:Name="treeView"
12+
ChildPropertyName="SubFiles"
13+
ItemTemplateContextType="Node"
14+
AutoExpandMode="AllNodesExpanded"
15+
ItemsSource="{Binding ImageNodeInfo}"
16+
TapCommand="{Binding TreeViewTapCommand}">
17+
<syncfusion:SfTreeView.ItemTemplate>
18+
<DataTemplate>
19+
<Grid x:Name="grid" RowSpacing="0" >
20+
...
21+
</Grid>
22+
</DataTemplate>
23+
</syncfusion:SfTreeView.ItemTemplate>
24+
</syncfusion:SfTreeView>
25+
```
26+
27+
### View Model
28+
29+
In the command execution method, skip the navigation for nodes based on TreeViewNode.Level.
30+
31+
```csharp
32+
public class FileManagerViewModel
33+
{
34+
public FileManagerViewModel()
35+
{
36+
TreeViewTapCommand = new Command<object>(OnTapped);
37+
}
38+
39+
public Command<object> TreeViewTapCommand { get; set; }
40+
41+
private void OnTapped(object obj)
42+
{
43+
var node = obj as Syncfusion.TreeView.Engine.TreeViewNode;
44+
45+
if (node.Level == 0) return;
46+
47+
var newPage = new Views.NewPage();
48+
newPage.BindingContext = node;
49+
App.Current.MainPage.Navigation.PushAsync(newPage);
50+
}
51+
}
52+
```
53+
54+
## Requirements to run the demo
55+
56+
To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)
57+
58+
## Troubleshooting
59+
### Path too long exception
60+
If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

0 commit comments

Comments
 (0)