Forum Xamarin.Forms

How to customize the ViewCell at Runtime in ListView Xamarin Forms

Here I need to customize the cell for two conditions,

(1) If Image exists, then show the image and set the WidthRequest for Item's Description,
(2) If Image not exists, then show the Item's Description with Full Container that means Full Width.

I attached an image for example,


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you can have a grid with two columns. Column 1 is for "Lorem Ipsum..", Column 2 is for the image.

    You can bind a boolean property (IsImageExists) to Label.ColumnsSpan then, with a IValueConverter, convert the boolean value to 1 or 2 (exists 1, not exists 2)

    Bind IsImageExists to Image.IsVisible property

    I think it's enough

  • LandLuLandLu Member, Xamarin Team Xamurai

    You can also try the DataTemplateSelector:
    Create two different templates for the selector: one for your condition 1 and two for another.
    Then define a bool property in your model to decide which template needs to be displayed.
    This approach adapts more complicated different templates.

Sign In or Register to comment.