Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Add tap gesture only if VM gave a source

$
0
0

I'm not sure how to do this correctly in an MVVM setup.

So, I have two image items
<Image x:Name="ImageAdd1"/> <Image x:Name="ImageAdd2"/>

however, I want the user to be able to tap them and go to a website. the problem is my understanding is the images should be set via VM and the tap gesture should be set in the code behind on the view. However, add 2 may not have anything in it half the time as it displays 1 or 2 adds at random set by the VM. Additionally, they might not need this additional feature for all items.

the view shouldn't be aware of the VM, and same with the reverse, but can I write code in the view that checks this?

edit:

<Image Source="tapped.jpg"> <Image.GestureRecognizers> <TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped" NumberOfTapsRequired="2" /> </Image.GestureRecognizers> </Image>

oh i can add it via the XAML with binding right? and say Tapped="OnTapGestureRecognizerTapped({Bindingcontext addurl})"

that's still under the correct MVVM right? what if the URL is null though? will i just handle a null exception inside the method?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>