Xamarin.Forms. Optimization ListView










1















Can you give recommendations on how to optimize the ListView?
It slows down when scrolling.
My viewCell looks like this:



<Grid BackgroundColor="Binding ListViewCustomizer.ItemBorderColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

<Grid Margin="0, 0, 0, 1"
BackgroundColor="Binding ListViewCustomizer.ItemBackgroundColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.Triggers>
<DataTrigger Binding="Binding IsRead" TargetType="Grid" Value="true">
<Setter Property="BackgroundColor" Value="#bfe3fa" />
</DataTrigger>
</Grid.Triggers>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>

<ContentView Grid.RowSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="1, 1">
<ffimageloading:CachedImage x:Name="mainImage"
Source="news_placeholder.png"
LoadingPlaceholder="news_placeholder.png"
DownsampleToViewSize="false"
CacheDuration="x:Static constant:ImageConfig.PreviewImageCacheDuration"
ErrorPlaceholder="news_placeholder.png" Aspect="AspectFill"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Transformations="Binding IsRead, Converter=StaticResource BoolToTransformationConverter">
<ffimageloading:CachedImage.DownsampleHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</ffimageloading:CachedImage.DownsampleHeight>
</ffimageloading:CachedImage>
</ContentView>

<Grid Grid.Column="1" RowSpacing="0" Margin="10,10,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>

<Label Style="StaticResource BaseListItemLabelStyle" FormattedText="Binding ., Converter=StaticResource NewsItemToFormattedStringConveter"/>

<ctrl:ExtendedLabel
Grid.Row="1"
MultilineTrimming="True"
x:Name="content"
Style="StaticResource ListItemContentLabelStyle" />
</Grid>

</Grid>
</Grid>


Maybe something to replace something. Maybe should I replace all bindings with code-behind?



Help me please.










share|improve this question


























    1















    Can you give recommendations on how to optimize the ListView?
    It slows down when scrolling.
    My viewCell looks like this:



    <Grid BackgroundColor="Binding ListViewCustomizer.ItemBorderColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

    <Grid Margin="0, 0, 0, 1"
    BackgroundColor="Binding ListViewCustomizer.ItemBackgroundColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <Grid.Triggers>
    <DataTrigger Binding="Binding IsRead" TargetType="Grid" Value="true">
    <Setter Property="BackgroundColor" Value="#bfe3fa" />
    </DataTrigger>
    </Grid.Triggers>

    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="3*" />
    <ColumnDefinition Width="4*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="6*"/>
    <RowDefinition Height="4*"/>
    </Grid.RowDefinitions>

    <ContentView Grid.RowSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="1, 1">
    <ffimageloading:CachedImage x:Name="mainImage"
    Source="news_placeholder.png"
    LoadingPlaceholder="news_placeholder.png"
    DownsampleToViewSize="false"
    CacheDuration="x:Static constant:ImageConfig.PreviewImageCacheDuration"
    ErrorPlaceholder="news_placeholder.png" Aspect="AspectFill"
    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
    Transformations="Binding IsRead, Converter=StaticResource BoolToTransformationConverter">
    <ffimageloading:CachedImage.DownsampleHeight>
    <extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
    </ffimageloading:CachedImage.DownsampleHeight>
    </ffimageloading:CachedImage>
    </ContentView>

    <Grid Grid.Column="1" RowSpacing="0" Margin="10,10,10,0">
    <Grid.RowDefinitions>
    <RowDefinition Height="auto"/>
    <RowDefinition Height="auto"/>
    </Grid.RowDefinitions>

    <Label Style="StaticResource BaseListItemLabelStyle" FormattedText="Binding ., Converter=StaticResource NewsItemToFormattedStringConveter"/>

    <ctrl:ExtendedLabel
    Grid.Row="1"
    MultilineTrimming="True"
    x:Name="content"
    Style="StaticResource ListItemContentLabelStyle" />
    </Grid>

    </Grid>
    </Grid>


    Maybe something to replace something. Maybe should I replace all bindings with code-behind?



    Help me please.










    share|improve this question
























      1












      1








      1








      Can you give recommendations on how to optimize the ListView?
      It slows down when scrolling.
      My viewCell looks like this:



      <Grid BackgroundColor="Binding ListViewCustomizer.ItemBorderColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

      <Grid Margin="0, 0, 0, 1"
      BackgroundColor="Binding ListViewCustomizer.ItemBackgroundColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
      <Grid.Triggers>
      <DataTrigger Binding="Binding IsRead" TargetType="Grid" Value="true">
      <Setter Property="BackgroundColor" Value="#bfe3fa" />
      </DataTrigger>
      </Grid.Triggers>

      <Grid.ColumnDefinitions>
      <ColumnDefinition Width="3*" />
      <ColumnDefinition Width="4*" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
      <RowDefinition Height="6*"/>
      <RowDefinition Height="4*"/>
      </Grid.RowDefinitions>

      <ContentView Grid.RowSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="1, 1">
      <ffimageloading:CachedImage x:Name="mainImage"
      Source="news_placeholder.png"
      LoadingPlaceholder="news_placeholder.png"
      DownsampleToViewSize="false"
      CacheDuration="x:Static constant:ImageConfig.PreviewImageCacheDuration"
      ErrorPlaceholder="news_placeholder.png" Aspect="AspectFill"
      HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
      Transformations="Binding IsRead, Converter=StaticResource BoolToTransformationConverter">
      <ffimageloading:CachedImage.DownsampleHeight>
      <extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
      </ffimageloading:CachedImage.DownsampleHeight>
      </ffimageloading:CachedImage>
      </ContentView>

      <Grid Grid.Column="1" RowSpacing="0" Margin="10,10,10,0">
      <Grid.RowDefinitions>
      <RowDefinition Height="auto"/>
      <RowDefinition Height="auto"/>
      </Grid.RowDefinitions>

      <Label Style="StaticResource BaseListItemLabelStyle" FormattedText="Binding ., Converter=StaticResource NewsItemToFormattedStringConveter"/>

      <ctrl:ExtendedLabel
      Grid.Row="1"
      MultilineTrimming="True"
      x:Name="content"
      Style="StaticResource ListItemContentLabelStyle" />
      </Grid>

      </Grid>
      </Grid>


      Maybe something to replace something. Maybe should I replace all bindings with code-behind?



      Help me please.










      share|improve this question














      Can you give recommendations on how to optimize the ListView?
      It slows down when scrolling.
      My viewCell looks like this:



      <Grid BackgroundColor="Binding ListViewCustomizer.ItemBorderColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

      <Grid Margin="0, 0, 0, 1"
      BackgroundColor="Binding ListViewCustomizer.ItemBackgroundColor, Source=x:Static theme:ThemeManager.Theme" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
      <Grid.Triggers>
      <DataTrigger Binding="Binding IsRead" TargetType="Grid" Value="true">
      <Setter Property="BackgroundColor" Value="#bfe3fa" />
      </DataTrigger>
      </Grid.Triggers>

      <Grid.ColumnDefinitions>
      <ColumnDefinition Width="3*" />
      <ColumnDefinition Width="4*" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
      <RowDefinition Height="6*"/>
      <RowDefinition Height="4*"/>
      </Grid.RowDefinitions>

      <ContentView Grid.RowSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="1, 1">
      <ffimageloading:CachedImage x:Name="mainImage"
      Source="news_placeholder.png"
      LoadingPlaceholder="news_placeholder.png"
      DownsampleToViewSize="false"
      CacheDuration="x:Static constant:ImageConfig.PreviewImageCacheDuration"
      ErrorPlaceholder="news_placeholder.png" Aspect="AspectFill"
      HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
      Transformations="Binding IsRead, Converter=StaticResource BoolToTransformationConverter">
      <ffimageloading:CachedImage.DownsampleHeight>
      <extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
      </ffimageloading:CachedImage.DownsampleHeight>
      </ffimageloading:CachedImage>
      </ContentView>

      <Grid Grid.Column="1" RowSpacing="0" Margin="10,10,10,0">
      <Grid.RowDefinitions>
      <RowDefinition Height="auto"/>
      <RowDefinition Height="auto"/>
      </Grid.RowDefinitions>

      <Label Style="StaticResource BaseListItemLabelStyle" FormattedText="Binding ., Converter=StaticResource NewsItemToFormattedStringConveter"/>

      <ctrl:ExtendedLabel
      Grid.Row="1"
      MultilineTrimming="True"
      x:Name="content"
      Style="StaticResource ListItemContentLabelStyle" />
      </Grid>

      </Grid>
      </Grid>


      Maybe something to replace something. Maybe should I replace all bindings with code-behind?



      Help me please.







      xaml listview xamarin.forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 10:35









      ViktorViktor

      224




      224






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You packed quite a lot of stuff into that viewcell. Also changing data binding to code behind won't give you significant benefits performancewise.



          What is happening here is that all of these elements need to run layout passes, which requires time (performance). Now multiply that with the amount of items in your ListView. Good news however is, that this multiplication factor will be in your favour once you improve your view to do less layouting.



          What I would suggest:



          1) Don't use "Auto" height definitions, since that will need multiple layout passes until the final height has been determined



          2) Reduce the grids to one single grid and work with RowSpan and ColumnSpan properties to set your elements



          3) Is there a reason why you are using a content view? If I remember correctly you should be able to put the ffimageloading.cachedimage directly into a grid.



          For more information about how to optimize your xamarin forms layout performance, I would recomment this article: https://xamarininsider.com/2017/08/03/optimizing-layout-performance-in-xamarin-forms/






          share|improve this answer

























          • "Don't use "Auto" height definitions". And can I use "*" (star)?

            – Viktor
            Nov 29 '18 at 15:53











          • Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

            – Markus Michel
            Nov 29 '18 at 15:58











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298169%2fxamarin-forms-optimization-listview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You packed quite a lot of stuff into that viewcell. Also changing data binding to code behind won't give you significant benefits performancewise.



          What is happening here is that all of these elements need to run layout passes, which requires time (performance). Now multiply that with the amount of items in your ListView. Good news however is, that this multiplication factor will be in your favour once you improve your view to do less layouting.



          What I would suggest:



          1) Don't use "Auto" height definitions, since that will need multiple layout passes until the final height has been determined



          2) Reduce the grids to one single grid and work with RowSpan and ColumnSpan properties to set your elements



          3) Is there a reason why you are using a content view? If I remember correctly you should be able to put the ffimageloading.cachedimage directly into a grid.



          For more information about how to optimize your xamarin forms layout performance, I would recomment this article: https://xamarininsider.com/2017/08/03/optimizing-layout-performance-in-xamarin-forms/






          share|improve this answer

























          • "Don't use "Auto" height definitions". And can I use "*" (star)?

            – Viktor
            Nov 29 '18 at 15:53











          • Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

            – Markus Michel
            Nov 29 '18 at 15:58
















          1














          You packed quite a lot of stuff into that viewcell. Also changing data binding to code behind won't give you significant benefits performancewise.



          What is happening here is that all of these elements need to run layout passes, which requires time (performance). Now multiply that with the amount of items in your ListView. Good news however is, that this multiplication factor will be in your favour once you improve your view to do less layouting.



          What I would suggest:



          1) Don't use "Auto" height definitions, since that will need multiple layout passes until the final height has been determined



          2) Reduce the grids to one single grid and work with RowSpan and ColumnSpan properties to set your elements



          3) Is there a reason why you are using a content view? If I remember correctly you should be able to put the ffimageloading.cachedimage directly into a grid.



          For more information about how to optimize your xamarin forms layout performance, I would recomment this article: https://xamarininsider.com/2017/08/03/optimizing-layout-performance-in-xamarin-forms/






          share|improve this answer

























          • "Don't use "Auto" height definitions". And can I use "*" (star)?

            – Viktor
            Nov 29 '18 at 15:53











          • Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

            – Markus Michel
            Nov 29 '18 at 15:58














          1












          1








          1







          You packed quite a lot of stuff into that viewcell. Also changing data binding to code behind won't give you significant benefits performancewise.



          What is happening here is that all of these elements need to run layout passes, which requires time (performance). Now multiply that with the amount of items in your ListView. Good news however is, that this multiplication factor will be in your favour once you improve your view to do less layouting.



          What I would suggest:



          1) Don't use "Auto" height definitions, since that will need multiple layout passes until the final height has been determined



          2) Reduce the grids to one single grid and work with RowSpan and ColumnSpan properties to set your elements



          3) Is there a reason why you are using a content view? If I remember correctly you should be able to put the ffimageloading.cachedimage directly into a grid.



          For more information about how to optimize your xamarin forms layout performance, I would recomment this article: https://xamarininsider.com/2017/08/03/optimizing-layout-performance-in-xamarin-forms/






          share|improve this answer















          You packed quite a lot of stuff into that viewcell. Also changing data binding to code behind won't give you significant benefits performancewise.



          What is happening here is that all of these elements need to run layout passes, which requires time (performance). Now multiply that with the amount of items in your ListView. Good news however is, that this multiplication factor will be in your favour once you improve your view to do less layouting.



          What I would suggest:



          1) Don't use "Auto" height definitions, since that will need multiple layout passes until the final height has been determined



          2) Reduce the grids to one single grid and work with RowSpan and ColumnSpan properties to set your elements



          3) Is there a reason why you are using a content view? If I remember correctly you should be able to put the ffimageloading.cachedimage directly into a grid.



          For more information about how to optimize your xamarin forms layout performance, I would recomment this article: https://xamarininsider.com/2017/08/03/optimizing-layout-performance-in-xamarin-forms/







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 8:45

























          answered Nov 14 '18 at 11:03









          Markus MichelMarkus Michel

          1,457314




          1,457314












          • "Don't use "Auto" height definitions". And can I use "*" (star)?

            – Viktor
            Nov 29 '18 at 15:53











          • Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

            – Markus Michel
            Nov 29 '18 at 15:58


















          • "Don't use "Auto" height definitions". And can I use "*" (star)?

            – Viktor
            Nov 29 '18 at 15:53











          • Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

            – Markus Michel
            Nov 29 '18 at 15:58

















          "Don't use "Auto" height definitions". And can I use "*" (star)?

          – Viktor
          Nov 29 '18 at 15:53





          "Don't use "Auto" height definitions". And can I use "*" (star)?

          – Viktor
          Nov 29 '18 at 15:53













          Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

          – Markus Michel
          Nov 29 '18 at 15:58






          Yes, because "Auto" layouts the childs several times to determine the height being used. Star takes a fraction or the entire amount of the available space given by the parent element.

          – Markus Michel
          Nov 29 '18 at 15:58


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298169%2fxamarin-forms-optimization-listview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線