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 node data as CommandParameter for TreeView ItemTemplate content in Xamarin.Forms (SfTreeView)

Platform: Xamarin.Forms |
Control: SfTreeView

You can bind the node item to CommandParameter in Xamarin.Forms SfTreeview by binding with dot.



ItemInfoCommand defined to get the node data in the ViewModel.

public class FileManagerViewModel
    public Command<object> NodeCommand { get; set; }
    public FileManagerViewModel()
        NodeCommand = new Command<object>(OnNodeExecuted);
    public void OnNodeExecuted(object data)
        App.Current.MainPage.DisplayAlert("Alert", (data as FileManager).ItemName.ToString() , "OK");


Binding (.) dot to CommandParameter of ViewModel command and will get the node data in the handler.

<Grid Grid.Column=”1”
    <Label LineBreakMode="NoWrap" TextColor="Black"
            Text="{Binding ItemName}"
    <Button Grid.Column="1" HorizontalOptions="End" Text="Node Data" CommandParameter="{Binding . }" 
    Command="{Binding Path=BindingContext.NodeCommand, Source={x:Reference treeView}}"/>

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