Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlexandraDonatiFMConway opened this issue Sep 26, 2024 · 0 comments

Comments

@AlexandraDonatiFMConway

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! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant