0

我有一个运行良好的轮播视图。我想要的只是单击此轮播视图中的图像时,如果图像名称为“monthly.jpg”,则显示警报或导航或...

我的 xaml 代码如下:

<CarouselView x:Name="CV">
    <CarouselView.ItemTemplate>
        <DataTemplate>
            <Frame WidthRequest="400">
                <Frame
                    BackgroundColor="Red"
                    HasShadow="True"
                    HeightRequest="240"
                    WidthRequest="300"
                    HorizontalOptions="CenterAndExpand"
                    CornerRadius="10"
                    Margin="10"
                    Padding="0">
                    
                    <Grid>
                        <StackLayout BackgroundColor="White">
                            <Image
                                Source="{Binding imgSource}"
                                Aspect="AspectFill"
                                ClassId="{Binding imgSource}"
                                HeightRequest="350">
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer
                                        Tapped="TapGestureRecognizer_OnTapped"
                                        NumberOfTapsRequired="1">

                                    </TapGestureRecognizer>
                                </Image.GestureRecognizers>
                            </Image>
    ....

我的代码是:

private void TapGestureRecognizer_OnTapped(object sender, EventArgs e)
{
    //string text = ((Image)sender).ClassId;

    Image image = (Image)sender;
    string imageString = image.ClassId;

    if (imageString == "monthly.jpg")
    {
        DisplayAlert("Go Go", "Please Try Egain", "Continue");
    }
}

但是当我单击图像时,什么也没有发生。我哪里错了??我是否正确使用了 classID 还是什么?

4

1 回答 1

0

感谢您为解决我的问题所花费的所有答案和时间。无论如何,我将我的点击手势更改为在 Grid 处触发并提供我的 Grid Class ID。该程序现在有效。

private void TapGestureRecognizer_Tapped_1(object sender, EventArgs e)
        {
            var check = (Grid)sender;

            string imageString = check.ClassId;

            if (imageString == "daily check")
            {
                DisplayAlert("Day", "Please Try Egain", "Continue");
            }
于 2021-08-03T15:12:58.870 回答