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"。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM