We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind data using FreshMVVM in Xamarin.Forms TreeView (SfTreeView) ?

The Xamarin.Forms SfTreeView allows you to work with FreshMVVM framework. Please follow the below steps to work with FreshMVVM,

Step 1: Install the FreshMvvm NuGet package in the shared code project. 

Step 2: Create your XAML page (view) with name ending with “Page”.

namespace TreeViewXamarin
    public partial class TreeViewPage : ContentPage
        public TreeViewPage()

Step 3: Create a page model with the name ending with PageModel and inherit FreshBasePageModel. If your Page name is MainPage, then the PageModel name should be MainPageModel and the namespace of Page and PageModel should be the same. In this PageModel, you can keep the ViewModel related properties.

using FreshMvvm;
public class TreeViewPageModel : FreshBasePageModel
    private ObservableCollection<FileManager> imageNodeInfo;
    public TreeViewPageModel()
    public ObservableCollection<FileManager> ImageNodeInfo
        get { return imageNodeInfo; }
        set { this.imageNodeInfo = value; }
    private void GenerateSource()

Step 4: Create model class which inherits FreshBasePageModel and use RaisePropertyChanged method of base class to raise property changed notifier.

namespace TreeViewXamarin
    public class FileManager : FreshBasePageModel
        private ObservableCollection<FileManager> subFiles;
        public FileManager()
        public ObservableCollection<FileManager> SubFiles
            get { return subFiles; }
                subFiles = value;

Step 5: Set MainPage using PageModel in your App.xaml.cs file.

public App()
    var page = FreshPageModelResolver.ResolvePageModel<TreeViewPageModel>();
    var basicNavContainer = new FreshNavigationContainer(page);
    MainPage = basicNavContainer;

Step 6: Bind the viewmodel collection to the SfTreeView.ItemSource property.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:syncfusion=" clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms"
            <syncfusion:SfTreeView x:Name="treeView"
                           ItemsSource="{Binding ImageNodeInfo}">
                <Grid x:Name="grid" >
                        <RowDefinition Height="*" />
                        <RowDefinition Height="1" />
                    <Grid Grid.Row="0">
                            <ColumnDefinition Width="40" />
                            <ColumnDefinition Width="*" />
                        <Grid >
                            <Image Source="{Binding Content.ImageIcon}"/>
                        <Grid Grid.Column="1">             
                            <Label Text="{Binding Content.ItemName}"/>
                    <StackLayout Grid.Row="1"/>

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile