GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - SyncfusionExamples/conditional-navigation-treeview-xamarin: How to do conditional navigation in Xamarin.Forms TreeView (SfTreeView)

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
TreeViewXamarin
TreeViewXamarin
 
 
README.md
README.md
 
 

Repository files navigation

conditional-navigation-treeview-xamarin

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.

Sample

XAML

Bind the SfTreeView.TapCommand to navigate to another page. By default, the TreeViewNode is the command parameter for the TapCommand.

<syncfusion:SfTreeView x:Name="treeView" 
                    ChildPropertyName="SubFiles"
                    ItemTemplateContextType="Node"
                    AutoExpandMode="AllNodesExpanded"
                    ItemsSource="{Binding ImageNodeInfo}"
                    TapCommand="{Binding TreeViewTapCommand}">
    <syncfusion:SfTreeView.ItemTemplate>
        <DataTemplate>
            <Grid x:Name="grid" RowSpacing="0" >
                ...
            </Grid>
        </DataTemplate>
    </syncfusion:SfTreeView.ItemTemplate>
</syncfusion:SfTreeView>

View Model

In the command execution method, skip the navigation for nodes based on TreeViewNode.Level.

public class FileManagerViewModel
{
    public FileManagerViewModel()
    {
        TreeViewTapCommand = new Command<object>(OnTapped);
    }
 
    public Command<object> TreeViewTapCommand { get; set; }
 
    private void OnTapped(object obj)
    {
        var node = obj as Syncfusion.TreeView.Engine.TreeViewNode;
 
        if (node.Level == 0) return;
 
        var newPage = new Views.NewPage();
        newPage.BindingContext = node;
        App.Current.MainPage.Navigation.PushAsync(newPage);
    }
}

Requirements to run the demo

To run the demo, refer to System Requirements for Xamarin

Troubleshooting

Path too long exception

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.

About

How to do conditional navigation in Xamarin.Forms TreeView (SfTreeView)

Topics

navigationsftreeviewtreeviewtreeviewnodexamarinxamarin-forms

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

3 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.