xamarin.fourm 中的可点击轮播视图
Clickable carouselview in xamarin.fourm
我有一个轮播视图,效果很好。我想要的只是单击此轮播视图中的图像,如果图像名称为“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 还是什么?
感谢您为解决我的问题提供的所有答案和时间。无论如何,我将我的 Tapping 手势更改为在 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");
}
我有一个轮播视图,效果很好。我想要的只是单击此轮播视图中的图像,如果图像名称为“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 还是什么?
感谢您为解决我的问题提供的所有答案和时间。无论如何,我将我的 Tapping 手势更改为在 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");
}