Esempio n. 1
0
            public MessageCell()
            {
                this.SetBinding(TextProperty, "Subject");
                this.SetBinding(DetailProperty, "MessagePreview");

                var delete = new MenuItem {
                    Text = "Delete", IsDestructive = true
                };

                delete.SetBinding(MenuItem.CommandProperty, "Delete");

                var mark = new MenuItem {
                    Text = "Mark", Icon = "calculator.png"
                };
                var move = new MenuItem {
                    Text = "Move"
                };

                //move.Clicked += async (sender, e) => await Navigation.PopAsync();

                ContextActions.Add(mark);
                ContextActions.Add(delete);
                ContextActions.Add(move);

                var clear = new MenuItem {
                    Text = "Clear Items"
                };

                clear.Clicked += (sender, args) => ContextActions.Clear();
                ContextActions.Add(clear);
            }
Esempio n. 2
0
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();

            var VM = BindingContext as CellViewModelBase;

            if (VM == null)
            {
                return;
            }
            ContextActions.Clear();
            if (VM.IsEditable)
            {
                var menuRemove = new MenuItem
                {
                    Text          = "Rimuovi",
                    IsDestructive = true
                };
                menuRemove.Clicked += (sender, e) =>
                {
                    var item = (CellViewModelBase)BindingContext; if (item == null)
                    {
                        return;
                    }
                };
            }
        }
 private void Reset()
 {
     NameLabel.Text        = "";
     AmountLabel.Text      = "";
     MinusButton.IsVisible = false;
     Image.Source          = null;
     ContextActions.Clear();
 }
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();
            Reset();

            if (ViewModel != null)
            {
                var foodstuff  = ViewModel.Foodstuff;
                var amountText = ViewModel.RequiredAmount.Match(
                    a => $"{ViewModel.Amount} / {a} {foodstuff.BaseAmount.Unit.ToString()}",
                    _ => foodstuff.BaseAmount.WithCount(ViewModel.Amount).ToString()
                    );

                NameLabel.Text        = ViewModel.Foodstuff.Name;
                AmountLabel.Text      = amountText;
                MinusButton.IsVisible = ViewModel.OnMinus != null;
                Image.Source          = ViewModel.Foodstuff.ImageUrl;

                var actions = ViewModel.MenuActions.Select(a => Controls.Controls.MenuItem(a));
                ContextActions.Clear();
                actions.ForEach(a => ContextActions.Add(a));
            }
        }