Templates in ListView

InfernnoInfernno USMember ✭✭
edited April 8 in Xamarin.Forms

Hello everyone,
I have a ListView with DataTemplateSelector and templates with common elements. I want to simplify them by moving common pieces to the base template and reuse them in child templates.

Base template code:

<!-- Label -->

/* Here we put stuff from derivatives */

<!-- Button -->

Child template code:

<!-- Image -->
<!-- Checkbox -->

And visually it will look like:

<!-- Label-->

<!-- Image -->
<!-- Checkbox -->

<!-- Button -->

The same goes for other child templates.

How I can accomplish this?
Previously I tried ContentTemplates/ContentPresentor along with ContentView but that didn't work. It seems that they are designed for ContentPage.

P.S. Order is important.

Answers

  • AsurAsur USMember ✭✭✭
    edited April 8

    not understanding the issue here you can have a stack layout and add content view with image and checkbox on some condition or show hide it based on a certain condition which in your case can be decided using the selector

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    If you make a custom ViewCell with the View property being a ContentView, you should be able to apply a ControlTemplate to it.

  • InfernnoInfernno USMember ✭✭
    edited April 9

    @Asur said:
    not understanding the issue here

    Well, shortly the whole point of this question is how to embed XAML code. I mean, I want to reuse xaml markup by declaring common elemets in parent templates and include them in child templates.

    @Asur said:
    you can have a stack layout and add content view with image and checkbox on some condition or show hide it based on a certain condition which in your case can be decided using the selector

    It can be a Grid too.

  • AsurAsur USMember ✭✭✭

    @Inferno I think you are going in the opposite direction here. Once can have a Parent layout and then add child layout into the page . But adding parent layout's element into the child view and that too at different places isn't possible as per my knowledge unless you create different layouts for different controls but by application it would become a child layout and not parent .
    @JoeManke's answer seem feasible where you have a layout with label and button and then in between add another child layout with image and checkbox

Sign In or Register to comment.