Extending ContentView with "templated" layout

MihaMarkicMihaMarkic SI ✭✭✭✭

I'm thinking about how to apply some template to each page, or better, to a layout.
Imagine you have few pages and each of them having a button at the bottom and a label on the top (just for the sample's sake). The rest is custom content.
Even more simplified than the above, I am thinking of a layout like:



where out of the box ContentView does only:

One of the way this would be possible is by inheriting ContentView and hack it a bit - because it has only Content property and it is difficult to combine the template and the actual content.

Basically if Xamarin provided a way to combine template and content like XAML does through i.e. ControlTemplate it'd be awesome. Or just some virtual methods that would allow that cleanly.

Answers

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    I made it by a base class, setting the content to a StackLayout, which contains the text at the top, a StackLayout in the middle and a button below the StackLayout. The StackLayout is a property of the base class. With this, you could add whatever you want to the StackLayout in the middle, but text and button allways at the same position.

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Darn, it cut out my XAML sample code.
    Yes, using code is a no brainer, but I'd really like it fo XAML.

    Like I'd define (preferably in XAML) the MyCustomControl's template, i.e.:

    ... <ControlTemplate> <Grid> <ContentControl /> <!-- here goes custom content --> </Grid> </ControlTemplate>

    and then use such a control it in page i.e.:

    ... <MyCustomControl> <!-- custom content --> </MyCustomControl>

    and the output would be:

    <Grid> <!-- custom content --> </Grid>

Sign In or Register to comment.