xamarin - 如何在 Xamarin Forms 中打开滑动时更改滑动视图内容的不透明度?
问题描述
我想在滑动过程中更改不透明度。有没有我可以用来做这件事的事件,如果有的话,有没有人有任何例子说明他们是如何做到这一点的。我想要的是当滑动区域完全显示时,滑动背景的不透明度从 100% 变为 0%。
解决方案
欢迎来到 SO!
我不确定这是否是您想要的,您可以尝试一下SwipeEnded
并SwipeChanging
检查一下。
Xaml 代码(基于官方示例)如下:
...
<SwipeView SwipeEnded="SwipeView_SwipeEnded" SwipeChanging="SwipeView_SwipeChanging">
<SwipeView.LeftItems>
<SwipeItems SwipeBehaviorOnInvoked="Close"
Mode="Reveal">
<SwipeItem Text="Favorite"
IconImageSource="favorite.png"
BackgroundColor="LightGreen"
Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.FavoriteCommand}"
CommandParameter="{Binding}" />
<SwipeItem Text="Delete"
IconImageSource="delete.png"
BackgroundColor="LightPink"
Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.DeleteCommand}"
CommandParameter="{Binding}" />
</SwipeItems>
</SwipeView.LeftItems>
...
ContentPage 将Opacity
在SwipeChanging
调用时更改。并且在调用时SwipeEnded
设置Opacity
为1
。
private void SwipeView_SwipeEnded(object sender, SwipeEndedEventArgs e)
{
Console.WriteLine("SwipeView_SwipeEnded");
var swipView = sender as SwipeView;
swipView.Opacity = 1;
}
private void SwipeView_SwipeChanging(object sender, SwipeChangingEventArgs e)
{
var swipView = sender as SwipeView;
swipView.Opacity = e.Offset/ swipView.Width;
}
效果:
推荐阅读
- bash - 访问运行脚本的 docker 容器外部的 bash 脚本变量
- amazon-web-services - AWS 未找到新创建的 RDS 快照
- kubernetes - host_path 删除器仅支持 /tmp/.+ 但收到提供的 /mnt/disk/kafka
- python - %timeit 和重新分配变量
- php - laravel如何自定义资源中的内爆函数结构
- git - 如何在没有两个存储库的情况下在 git 中部署期间更改配置文件
- payment - 如何在 Spree 上根据信用卡类型使用不同的支付网关?
- amazon-web-services - 重用现有资源作为 cloudformation 中的参数
- python - 无法从 2.7-3.6 更改 python 版本
- ruby - 为什么 travis yml 构建失败?