Xamarin.Forms踩坑整理

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