Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Weird ImageButton behavior inside ListView

$
0
0

Hello all!!

I have an ImageButton inside a ListView. Everything is working perfectly (binds, tap events..). The XAML code is below.

<ImageButton
Source="more_options"
Aspect="AspectFit"
HorizontalOptions="End"
WidthRequest="21"
BackgroundColor="Transparent"
Clicked="OnMoreOptionsTapped"
CommandParameter="{Binding .}"
Grid.Column="2"
Grid.Row="0"/>

Except for one thing: media.giphy .com/ media/ vRJZHNHrc4Bych0ROJ/ giphy.gif (check gif please)

As you can see, some of the ImageButton's image gets super small as the ListView is scrolled back and forth. I don't know what is happening and I can't find no one who has gone through this. Anyone has any idea of what this can be and how it can be fixed?

Full XAML 'code': pastebin .com/ YDyhWCgm - ImageButton is at line 56.

Ah, I haven't tested it on iOS. Android only.


Now, I could use a common Image element with a TapGestureRecognizer to achieve my goal, but (and that's a big but) I need to get the Image's on screen coordinates on my code-behind, and I can't find anywhere how can I get the Image element having only the TapGestureRecognizer (with an ImageButton is super easy). I tried to do something like:

<Image
Source="more_options"
Aspect="AspectFit"
HorizontalOptions="End"
WidthRequest="21"
BackgroundColor="Transparent"
Grid.Column="2"
Grid.Row="0">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnMoreOptionsTapped"
CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>
</Image>

Code-behind:

private void OnMoreOptionsTapped(object sender, TappedEventArgs args)
{
var tapGesture = sender as TapGestureRecognizer;
var image= tapGesture.Parent as Image;
...
}

But tapGesture.Parent is null and tapGesture.Parent.Parent is null too. Yeah, i've tried it.


So,

  1. ImageButton bugs out on ListView. Any idea of how it can be fixed?
  2. Image works flawlessly, but it doesn't suit me, because I need to get the Image on my code-behind. Any idea of how can I get TapGestureRecognizer's parent? That would work for me.
  3. New account so I can't post straigth forward links. I'm sorry about that.

Thanks all :smile:


Viewing all articles
Browse latest Browse all 77050


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