Xamarin.Forms踩坑集锦(持续更新)

本文解决Xamarin.Forms开发中常见的UI问题,包括ImageButton图片大小变化、ListView行高调整等,并介绍DelegateCommand参数类型注意事项,以及使用SimpleAudioPlayer库加载音频文件的正确方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、ImageButton控件

问题:ImageButton在切换图片的时候,图片大小会改变。

Github Issue:ImageButton changes image size · Issue #4510 · xamarin/Xamarin.Forms

解决:使用Image控件,将Image.GestureRecognizers设置为TapGestureRecognizer,支持Event和Command。

<Image.GestureRecognizers>
  <TapGestureRecognizer NumberOfTapsRequired="1"
                Command="{Binding SwitchPlayPauseCommand}"
               CommandParameter="{Binding IsPlaying}"/>   </Image.GestureRecognizers>

 

2、DelegateCommand类

问题:Prism框架,DelegateCommand<T>,T为值类型时出错。

解决:参数类型T无法使用值类型,可以使用值类型的可空类型如int?。

 

3、mipmap文件夹

问题:新建项目使用Prism模板,在Android项目中的mipmap文件夹内的图片,Forms项目无法使用。

解决:手动建立drawable文件夹(不支持层级子文件夹),存放Forms使用的图片。

mipmap文件夹中的图片,可以在Android项目中使用。

 

4、SimpleAudioPlayer

问题:使用ISimpleAudioPlayer.Load(string fileName)加载音频文件后,获取到的ISimpleAudioPlayer.Duration不正确。

解决:使用ISimpleAudioPlayer.Load(Stream audioStream)。

 

5、MasterDetailPage

问题:MasterDetailPage.Master设置为ContentPage,设置ContentPage.BackgroundImage无效。

解决:ContentPage.BackgroundColor="Transparent"。

 

6、ListView

问题:ListView的行高度,不随ViewCell的高度而改变。

解决:ListView.HasUnevenRows="True"。

转载于:https://www.cnblogs.com/MrEggplant/p/10240021.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值