MAUI中如何让CarouselView响应CurrentItemChanged事件?
MAUI CarouselView CurrentItem绑定与CurrentItemChanged事件失效问题解决
问题场景
使用MAUI的CarouselView控件时,需要实现获取当前选中项并监听其变化的功能,编写的代码如下:
<CarouselView VerticalOptions="Center" PeekAreaInsets="65" Loop="True" ItemsSource="{Binding Minutes}" CurrentItem="{Binding SelectedMinute}" CurrentItemChanged="carouselMinutes_CurrentItemChanged"> <CarouselView.ItemsLayout>
遇到的问题:
- 默认
CurrentItem属性完全无法正常工作 - 注册
CurrentItemChanged事件后,滚动控件时该事件从未触发
解决办法
升级到.NET 8预览版后,上述问题已完全解决,CarouselView控件的CurrentItem绑定和CurrentItemChanged事件均能正常使用。
内容的提问来源于stack exchange,提问作者Toto
相关产品推荐
相关产品推荐

