Xamarin.Forms 效能改善

共用技巧

  • 儘量簡少tag的使用,例如包了StackyLayout,但裏面只有一個元素
  • XamlCompilation 要加,在complier可除錯,並提昇xaml速度 (Ref)
-- AssemblyInfo.cs
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
-- class level
[XamlCompilation (XamlCompilationOptions.Compile)]
  • 如果Stacklayout的定義許多,建議改用Grid
  • 安裝mvvm helper,把obserable rangecollection進行擴充
  • 減少屬性的使用
  • 使用Grid減少Auto的設定,此設定為依內容進行偵測,以固定寬度為高度為佳

ListView 基本技巧

  • CachingStrategy={RecycleElement} 通常都是用Recycle ,除非是30~40個以上的binding item才不用
<ListView CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
              ...
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
  • 如果一個listview裏面,有不同的template要套用,可以採用cell的TemplateSelector機制 (Ref)
  • 使用Built in cells,例如 TextCell, ImageCell (Ref)

results matching ""

    No results matching ""