public TasksPage(SQLiteAsyncConnection connection) { db = connection; Title = "Tasks"; Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, Children = { (listView = new ListView { ItemTemplate = new DataTemplate(() => { // edit button var editItem = new MenuItem { Text = "Edit", Command = new Command(async param => { var task = (TaskItem)param; await EditItem(task); }) }; editItem.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); // delete button var deleteItem = new MenuItem { Text = "Delete", IsDestructive = true, Command = new Command(async param => { var task = (TaskItem)param; await DeleteItem(task); }) }; deleteItem.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); // list item var cell = new TaskItemCell { ContextActions = { editItem, deleteItem } }; return(cell); }), }) } }; listView.ItemSelected += async(sender, e) => { if (e.SelectedItem != null) { var task = (TaskItem)e.SelectedItem; await CompleteItem(task); listView.SelectedItem = null; } }; var addButton = new ToolbarItem { Text = "Add", Command = new Command(async() => { await EditItem(null); }) }; ToolbarItems.Add(addButton); }
public TasksPage (SQLiteAsyncConnection connection) { db = connection; Title = "Tasks"; Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, Children = { (listView = new ListView { ItemTemplate = new DataTemplate (() => { // edit button var editItem = new MenuItem { Text = "Edit", Command = new Command (async param => { var task = (TaskItem)param; await EditItem (task); }) }; editItem.SetBinding (MenuItem.CommandParameterProperty, new Binding (".")); // delete button var deleteItem = new MenuItem { Text = "Delete", IsDestructive = true, Command = new Command (async param => { var task = (TaskItem)param; await DeleteItem (task); }) }; deleteItem.SetBinding (MenuItem.CommandParameterProperty, new Binding (".")); // list item var cell = new TaskItemCell { ContextActions = { editItem, deleteItem } }; return cell; }), }) } }; listView.ItemSelected += async (sender, e) => { if (e.SelectedItem != null) { var task = (TaskItem)e.SelectedItem; await CompleteItem (task); listView.SelectedItem = null; } }; var addButton = new ToolbarItem { Text = "Add", Command = new Command (async () => { await EditItem (null); }) }; ToolbarItems.Add (addButton); }