简体   繁体   中英

How to implement tap event on ImageCell in Xamarin Forms?

I am using ImageCell inside TableView to create various setting page.

<TableView Intent="Settings" HasUnevenRows="true">
    <TableRoot>
        <TableSection>
            <ImageCell x:Name="darkTheme" Text="Dark theme" />
            <ImageCell x:Name="lightTheme" Text="Light theme" />
        </TableSection>
    </TableRoot>
</TableView>

In my C# code I have the following:

lightTheme.Tapped += new EventHandler((e, s) =>
{
    Debug.WriteLine("Light theme tapped");
});

It's not being triggered everytime I tapped the image cell. Anyone knows how to properly implement a tap event in an ImageCell just like the TapGestureRecognizer in a ViewCell ?

Gathered from the extensive comments and chat I see that you had a custom renderer for the TableView in place. This renderer on iOS had the property AllowSelection set to false, effectively stopping you from selecting a cell and thus causing the tapped event not to be fired.

I just thought I'd put it up as a solution for future reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM