Xamarin Forms - adding the calling object as a parameter on a tap gesture recognizer










0














What is the correct syntax for adding the image in the XAML below as the parameter on the Command?



<ffimageloading:CachedImage Source="Binding Source" Aspect="AspectFit" CacheType="Memory" Opacity="2" x:Name="smallImage" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="Binding Path=BindingContext.SetImageCommand, Source=x:Reference this"
CommandParameter="Binding smallImage" />
</Image.GestureRecognizers>
</ffimageloading:CachedImage>


And the command code it's bound to (CustomCachedImage is just a class derived from a cached image, with an imageName field added)



There will be multiple instances of the calling image as it is in a data template as part of an image slider, so I can't just get the control by name I have to make sure it is the calling control being passed.



public ICommand SetImageCommand

get

return new Command<CustomCachedImage>((_image) =>

string imgName = _image.ImageName;
SetImg(imgName);
);











share|improve this question























  • Please show the object that you bind to it
    – Gerald Versluis
    Nov 12 at 15:20










  • thanks, post updated
    – DarkW1nter
    Nov 12 at 15:56










  • Please post all relevant code :-) What does SetImg do and where does smallImage come from?
    – Gerald Versluis
    Nov 12 at 15:57











  • There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
    – DarkW1nter
    Nov 12 at 16:00










  • Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
    – DarkW1nter
    Nov 12 at 16:01















0














What is the correct syntax for adding the image in the XAML below as the parameter on the Command?



<ffimageloading:CachedImage Source="Binding Source" Aspect="AspectFit" CacheType="Memory" Opacity="2" x:Name="smallImage" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="Binding Path=BindingContext.SetImageCommand, Source=x:Reference this"
CommandParameter="Binding smallImage" />
</Image.GestureRecognizers>
</ffimageloading:CachedImage>


And the command code it's bound to (CustomCachedImage is just a class derived from a cached image, with an imageName field added)



There will be multiple instances of the calling image as it is in a data template as part of an image slider, so I can't just get the control by name I have to make sure it is the calling control being passed.



public ICommand SetImageCommand

get

return new Command<CustomCachedImage>((_image) =>

string imgName = _image.ImageName;
SetImg(imgName);
);











share|improve this question























  • Please show the object that you bind to it
    – Gerald Versluis
    Nov 12 at 15:20










  • thanks, post updated
    – DarkW1nter
    Nov 12 at 15:56










  • Please post all relevant code :-) What does SetImg do and where does smallImage come from?
    – Gerald Versluis
    Nov 12 at 15:57











  • There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
    – DarkW1nter
    Nov 12 at 16:00










  • Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
    – DarkW1nter
    Nov 12 at 16:01













0












0








0







What is the correct syntax for adding the image in the XAML below as the parameter on the Command?



<ffimageloading:CachedImage Source="Binding Source" Aspect="AspectFit" CacheType="Memory" Opacity="2" x:Name="smallImage" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="Binding Path=BindingContext.SetImageCommand, Source=x:Reference this"
CommandParameter="Binding smallImage" />
</Image.GestureRecognizers>
</ffimageloading:CachedImage>


And the command code it's bound to (CustomCachedImage is just a class derived from a cached image, with an imageName field added)



There will be multiple instances of the calling image as it is in a data template as part of an image slider, so I can't just get the control by name I have to make sure it is the calling control being passed.



public ICommand SetImageCommand

get

return new Command<CustomCachedImage>((_image) =>

string imgName = _image.ImageName;
SetImg(imgName);
);











share|improve this question















What is the correct syntax for adding the image in the XAML below as the parameter on the Command?



<ffimageloading:CachedImage Source="Binding Source" Aspect="AspectFit" CacheType="Memory" Opacity="2" x:Name="smallImage" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="Binding Path=BindingContext.SetImageCommand, Source=x:Reference this"
CommandParameter="Binding smallImage" />
</Image.GestureRecognizers>
</ffimageloading:CachedImage>


And the command code it's bound to (CustomCachedImage is just a class derived from a cached image, with an imageName field added)



There will be multiple instances of the calling image as it is in a data template as part of an image slider, so I can't just get the control by name I have to make sure it is the calling control being passed.



public ICommand SetImageCommand

get

return new Command<CustomCachedImage>((_image) =>

string imgName = _image.ImageName;
SetImg(imgName);
);








xaml xamarin.forms gesture






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 15:47

























asked Nov 12 at 15:15









DarkW1nter

1,37043567




1,37043567











  • Please show the object that you bind to it
    – Gerald Versluis
    Nov 12 at 15:20










  • thanks, post updated
    – DarkW1nter
    Nov 12 at 15:56










  • Please post all relevant code :-) What does SetImg do and where does smallImage come from?
    – Gerald Versluis
    Nov 12 at 15:57











  • There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
    – DarkW1nter
    Nov 12 at 16:00










  • Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
    – DarkW1nter
    Nov 12 at 16:01
















  • Please show the object that you bind to it
    – Gerald Versluis
    Nov 12 at 15:20










  • thanks, post updated
    – DarkW1nter
    Nov 12 at 15:56










  • Please post all relevant code :-) What does SetImg do and where does smallImage come from?
    – Gerald Versluis
    Nov 12 at 15:57











  • There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
    – DarkW1nter
    Nov 12 at 16:00










  • Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
    – DarkW1nter
    Nov 12 at 16:01















Please show the object that you bind to it
– Gerald Versluis
Nov 12 at 15:20




Please show the object that you bind to it
– Gerald Versluis
Nov 12 at 15:20












thanks, post updated
– DarkW1nter
Nov 12 at 15:56




thanks, post updated
– DarkW1nter
Nov 12 at 15:56












Please post all relevant code :-) What does SetImg do and where does smallImage come from?
– Gerald Versluis
Nov 12 at 15:57





Please post all relevant code :-) What does SetImg do and where does smallImage come from?
– Gerald Versluis
Nov 12 at 15:57













There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
– DarkW1nter
Nov 12 at 16:00




There is a larger main image, the tap gesture recognizer calls SetImg which set the image to the same source as the smaller image in the slider the user has tapped. Everything else works I just can't seem to pass the tapped image as a parameter to the command.
– DarkW1nter
Nov 12 at 16:00












Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
– DarkW1nter
Nov 12 at 16:01




Should have mentioned, the image sources can be either bundled in the app or held in local storage, hence the custom cahcedImage. If I can pass the image, I can grab the image name and do the rest easily.
– DarkW1nter
Nov 12 at 16:01












1 Answer
1






active

oldest

votes


















0














changed "Binding smallImage" to "Binding ." and I got what I needed






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265075%2fxamarin-forms-adding-the-calling-object-as-a-parameter-on-a-tap-gesture-recogn%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    changed "Binding smallImage" to "Binding ." and I got what I needed






    share|improve this answer

























      0














      changed "Binding smallImage" to "Binding ." and I got what I needed






      share|improve this answer























        0












        0








        0






        changed "Binding smallImage" to "Binding ." and I got what I needed






        share|improve this answer












        changed "Binding smallImage" to "Binding ." and I got what I needed







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 16:30









        DarkW1nter

        1,37043567




        1,37043567



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265075%2fxamarin-forms-adding-the-calling-object-as-a-parameter-on-a-tap-gesture-recogn%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto