Forum Cross Platform with Xamarin

Binding Commands to Button inside GridView

brianduccabrianducca ARMember ✭✭

Hello! i'm having some issues with binding. The command is not binding and i don't know why.
I'm working with PCL targeting iOS & Android.
I need to raise a pop up when user clicks on that button, for that, i'm using this
Then after submitting that popup, i need to change the text & disable that button (now, i'm doing that in submit button inside the PopUp Page).
In this line
var page = new PopUp(Guid.NewGuid(), b.Text,b);
I don't know if it's the best way to do it.
Here is my code.


        eVM = new EViewModel();

            gv = new GridView();
            gv.MaxColumns = 3;
            gv.ItemsSource = eVM.EPCategories;
            gv.ItemTemplate = new DataTemplate(typeof(CustomCategoryCell));

            this.BindingContext = eVM;


public class CustomCategoryCell:ViewCell
        public CustomCategoryCell()
            Button b = new Button();
            b.SetBinding(Button.TextProperty, "Name");
            b.SetBinding(Button.BackgroundColorProperty, "BackgroundColor");
            b.SetBinding(Button.CommandProperty, "ClickedCommand" );
    b.SetBinding(Button.CommandParameterProperty, ".");
            b.HorizontalOptions = LayoutOptions.FillAndExpand;
            b.VerticalOptions = LayoutOptions.FillAndExpand;
            b.TextColor = Color.Black;

            var viewLayout = new StackLayout()
                Orientation = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children = { b}

            View = viewLayout;




 public class EViewModel
        public ObservableCollection<PCategory> EPCategories{ get; }

        public EViewModel()

            using (var db = new DB())
                EPCategories= new ObservableCollection<PCategory>(db.GetPCategories());

            this.ClickedCommand=new Command((sender) =>
            Button b = (Button)sender;
            if (b.Text != "Completed")

                var page = new PopUp(Guid.NewGuid(), b.Text,b);

        // ICommand implementations
        public ICommand ClickedCommand { private set; get; }


Best Answer


Sign In or Register to comment.