Last active
October 14, 2015 06:46
-
-
Save Vaikesh/ac944ec17a2229c40e30 to your computer and use it in GitHub Desktop.
Handle events in listview view cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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