我已经尝试了一段时间,现在使我的carousel视图可点击,并使用它来导航到其他页面/shell。下面是我的代码:
<CarouselView ItemsSource="{Binding Games}" HeightRequest="280" PeekAreaInsets="100">
<CarouselView.ItemTemplate>
<DataTemplate x:DataType="viewmodels:NewGames">
<StackLayout>
<Frame HeightRequest="300"
WidthRequest="180"
BackgroundColor="white"
Padding="0"
CornerRadius="10"
HasShadow="True"
Margin="15"
HorizontalOptions="CenterAndExpand">
<Grid>
<StackLayout BackgroundColor="DimGray">
<Image Source="{Binding ImageSource}" Aspect="AspectFill">
</Image>
</StackLayout>
<StackLayout Margin="-5">
<Label Text="{Binding GameTitle}"
TextColor="PaleGoldenrod"
FontSize="18"
FontAttributes="Bold"
Margin="15"
VerticalOptions="EndAndExpand"/>
</StackLayout>
</Grid>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
我在carousel视图选项卡下查看了xamarin文档,但没有发现任何有用的内容。
您可以尝试像Jason下面建议的那样将TapGestureRecognizer
添加到Frame
。
Xaml:
<CarouselView ItemsSource="{Binding Games}" HeightRequest="280" PeekAreaInsets="100">
<CarouselView.ItemTemplate>
<DataTemplate x:DataType="viewmodels:NewGames">
<StackLayout>
<Frame HeightRequest="300"
WidthRequest="180"
BackgroundColor="white"
Padding="0"
CornerRadius="10"
HasShadow="True"
Margin="15"
HorizontalOptions="CenterAndExpand">
<Frame.GestureRecognizers>
<TapGestureRecognizer
Tapped="TapGestureRecognizer_Tapped">
</TapGestureRecognizer>
</Frame.GestureRecognizers>
<Grid>
<StackLayout BackgroundColor="DimGray">
<Image Source="{Binding ImageSource}" Aspect="AspectFill">
</Image>
</StackLayout>
<StackLayout Margin="-5">
<Label Text="{Binding GameTitle}"
TextColor="PaleGoldenrod"
FontSize="18"
FontAttributes="Bold"
Margin="15"
VerticalOptions="EndAndExpand"/>
</StackLayout>
</Grid>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
后台代码:
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
//navigate to other pages/shells
await Navigation.PushModalAsync(new Page1());
}