locked
How do i pass command parameter on a label in xamarin forms RRS feed

  • Question

  • User355323 posted

    I want to add command parameter on a label in xamarin forms

    Wednesday, March 7, 2018 1:14 PM

Answers

  • User271590 posted

    https://pastebin.com/B6qmPrjb

    This?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 1:31 PM
  • User180523 posted

    You don't. That's what people are trying to tell you. A Label doesn't have a CommandParameter property because a Label doesn't have a Command. No Command so no CommandParamter.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 1:53 PM
  • User76049 posted

    @Ajay87

    The answers to your question are all correct.

    You could create your own custom label based on the label control and add command and command parameter capabilities like I did with this image button control

    https://github.com/mackayn/CrudSample/blob/master/CrudSample/CustomControls/ImageButton.cs

    The point is you'd still need a gesture recognizer to fire the command when the UIElement is tapped...like the sample above does.

    If you doesn't provide a use case scenario for why you want this particular behavior people will assume your misunderstanding usage of the Forms framework. You need to give as a little more than "I want both".

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 3:57 PM

All replies

  • User271590 posted

    Why would you need a command on a label? A label is used just to show information to the user, not for interaction. If you want to use command then you should use Button.

    Wednesday, March 7, 2018 1:17 PM
  • User180523 posted

    Or TapGestureRecognizer so you can tap on the Label. The recognizer would then get a command and parameter

    Wednesday, March 7, 2018 1:25 PM
  • User271590 posted

    https://pastebin.com/B6qmPrjb

    This?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 1:31 PM
  • User355323 posted

    @ClintStLaurent I want to add both TapGestureRecognizer and command parameter on a label..

    Wednesday, March 7, 2018 1:43 PM
  • User180523 posted

    Ok. Well there are plenty of tutorials and walkthroughs on adding TapGestureRecongizer. https://www.google.com/search?q=tapgesturerecognizer+%3Axamairn&ie=utf-8&oe=utf-8&client=firefox-b-1-ab

    Wednesday, March 7, 2018 1:49 PM
  • User355323 posted

    @RicardoJarree How can i access the command parameter on xaml.cs page . Thanks

    Wednesday, March 7, 2018 1:51 PM
  • User180523 posted

    You don't. That's what people are trying to tell you. A Label doesn't have a CommandParameter property because a Label doesn't have a Command. No Command so no CommandParamter.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 1:53 PM
  • User355323 posted

    @ClintStLaurent I know how to use TapGestureRecongizer, but i want both functionality thats why i posted this query here.

    Wednesday, March 7, 2018 2:04 PM
  • User180523 posted

    You can want anything. That's great. But it doesn't change the reality of what is available.

    Wednesday, March 7, 2018 3:14 PM
  • User76049 posted

    @Ajay87

    The answers to your question are all correct.

    You could create your own custom label based on the label control and add command and command parameter capabilities like I did with this image button control

    https://github.com/mackayn/CrudSample/blob/master/CrudSample/CustomControls/ImageButton.cs

    The point is you'd still need a gesture recognizer to fire the command when the UIElement is tapped...like the sample above does.

    If you doesn't provide a use case scenario for why you want this particular behavior people will assume your misunderstanding usage of the Forms framework. You need to give as a little more than "I want both".

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 7, 2018 3:57 PM
  • User355323 posted

    @NMackay Thanks, it will help

    Wednesday, March 7, 2018 5:00 PM