Skip to content

Instantly share code, notes, and snippets.

@Vaikesh
Last active October 14, 2015 06:46
Show Gist options
  • Save Vaikesh/ac944ec17a2229c40e30 to your computer and use it in GitHub Desktop.
Save Vaikesh/ac944ec17a2229c40e30 to your computer and use it in GitHub Desktop.
Handle events in listview view cell
using System;
using Xamarin.Forms;
namespace LeoSample
{
// Page containning list
public class MyPage : ContentPage
{
ListView lstView;
public MyPage ()
{
lstView = new ListView { };
lstView.ItemTemplate = new DataTemplate(typeof(SampleCell)); //Datatemplate
Content = new StackLayout {
Children = {
lstView
}
};
}
}
//View Cell for list
public class SampleCell : ViewCell
{
public SampleCell()
{
Button editBtn = new Button
{
HorizontalOptions = LayoutOptions.StartAndExpand
};
Button deleteBtn = new Button
{
HorizontalOptions = LayoutOptions.StartAndExpand
};
//------------ Set Value Binding--------------
//
// editBtn.SetBinding (Button.CommandParameterProperty, new Binding ("."));
// deleteBtn.SetBinding (Button.CommandParameterProperty, new Binding ("."));
//
//
editBtn.Clicked += (s, e) => {
App.Current.MainPage.DisplayAlert("Alert","Edit Button","Ok");
//App.Current.MainPage.Navigation.PushAsync( <<_Your Page here_>>, true);
};
deleteBtn.Clicked += (s, e) => {
App.Current.MainPage.DisplayAlert("Alert","Delete Button","Ok");
};
View = new StackLayout {
Children = {
editBtn,deleteBtn
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment