public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.list, menu); var item = menu.FindItem(Resource.Id.list_add); item.ActionView.Click += (v, args) => { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Add a to-do"); EditText input = new EditText(this); input.SetSingleLine(true); builder.SetView(input); builder.SetPositiveButton("OK", (dialog, which) => { viewModel.AddItem(input.Text); }); builder.SetNegativeButton("Cancel", (dialog, which) => { }); builder.Show(); }; return(true); }
private void AddItem(object sender, System.EventArgs e) { var input = (sender as Entry); if (input.Text == string.Empty) { return; } var text = input.Text.Trim().Split(' '); var amount = text.Where(i => i.All(char.IsDigit)).FirstOrDefault() ?? "1"; var product = String.Join( " ", text.Where(i => !i.All(char.IsDigit)).ToArray() ); model.AddItem(new Item(new Product(product), int.Parse(amount))); input.Text = String.Empty; input.Focus(); #pragma warning disable model.Save(); #pragma warning restore }
public ViewModel() { listViewModel = new ListViewModel(); ListViewModel.AddItem(); gridViewModel = new GridViewModel(); }