Giter Club home page Giter Club logo

treeview-command-parameter-xamarin's Introduction

How to bind node data as CommandParameter for TreeView ItemTemplate content in Xamarin.Forms (SfTreeView)

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

You can also refer the following article.

https://www.syncfusion.com/kb/11406/how-to-bind-node-data-as-commandparameter-for-treeview-itemtemplate-content-in-xamarin

C#

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");
    }
}

XAML

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

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

treeview-command-parameter-xamarin's People

Contributors

jayaleshwari avatar sarubala20 avatar vinothkumar-ganesan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.