Skip to content

Button command in DataTemplate NOT working in Android mobile app #139

Description

Hi,
I have a button in one page which works using markup with either these lines of code

  1. .Bind(Button.CommandProperty, nameof(DeliveryCollectionDetailsPageViewModel.CompleteOrderCommand))
  2. .BindCommand(static (DeliveryCollectionDetailsPageViewModel vm) => vm.CompleteOrderCommand, mode: BindingMode.OneWay)

I have another page with a CollectionView who's template I define in another file under Views which contains a button.
The above 2 lines don't work in the DataTemplate and neither di the following.

  1. .Invoke(cv => {
    var tapGesture = new TapGestureRecognizer();
    tapGesture.SetBinding(TapGestureRecognizer.CommandProperty, "TakeRightPictureForConsignmentCommand");
    cv.GestureRecognizers.Add(tapGesture);
    })
    4).BindTapGesture( (ConsignmentPicturesViewModel vm) => vm.TakeRightPictureForConsignmentCommand)

5).Bind(Button.CommandProperty, getter: new Binding("TakeRightPictureForConsignmentCommand", source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(ConsignmentPicturesViewModel))))

6).Bind<Button, ConsignmentPicturesViewModel, ICommand>(
Button.CommandProperty,getter: (ConsignmentPicturesViewModel vm)=>vm.TakeRightPictureForConsignmentCommand,
new Binding("TakeRightPictureForConsignmentCommand",
source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor,
typeof(DeliveryCollectionDetailsPageViewModel)))

  1. .Bind<Button, ConsignmentPicturesViewModel, ICommand>(
    Button.CommandProperty,getter: nameof(ConsignmentPicturesViewModel.TakeRightPictureForConsignmentCommand)),
    new Binding("TakeRightPictureForConsignmentCommand",
    source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor,
    typeof(DeliveryCollectionDetailsPageViewModel)))

Before I give up and re-write the page in Xaml, do you have any suggestions?

Thanks! 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions