当用户触摸ImageButton时,我试图从我的***CarouselView***中删除图像。但我不知道如何在我的CarouselView中获取活动图像。
有人知道我怎么能这么做吗?
非常感谢!
代码页.xaml:
<StackLayout Padding="5">
<CarouselView x:Name="carousel" HeightRequest="600" IndicatorView="{x:Reference contImgs}">
<CarouselView.ItemTemplate>
<DataTemplate>
<Image x:Name="activeImg" Source="{Binding Source}" Aspect="AspectFill"></Image>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="contImgs" IndicatorColor="#bbb" SelectedIndicatorColor="#000" IndicatorSize="12" IndicatorsShape="Circle"></IndicatorView>
<ImageButton Source="drawable/icon_trash.png" WidthRequest="100" Clicked="btnDeleteImg" HeightRequest="100" AbsoluteLayout.LayoutBounds="0.98,0.07,50,50" AbsoluteLayout.LayoutFlags="PositionProportional"></ImageButton>
</StackLayout>
代码页. xaml.cs:
private List<Image> imgsCarrousel = new List<Image>();
private void btnDeleteImg(object sender, EventArgs e)
{
imgsCarrousel.Remove(imgSelected); // I want to achive something like this
}
2条答案
按热度按时间b5lpy0ml1#
如果您阅读
CarouselView
的文档,它同时具有Position
(当前索引)和CurrentItem
(实际对象)的属性kuhbmx9i2#
解决方案
我用这个来解决我的问题。我把我的代码留在这里了,也许它能帮到别人。
代码页.xaml:
代码页. xaml.cs: