Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How can I create a custom renderer for a decorated "container" view with custom renderer?

I'm basically trying to create a custom "container" view, which will render differently on each platform, but its content will render the standard way. Specifically this would be like a menu item which contains complicated views, but the outter decoration remains the same in all cases. You cam imagine it something like this


but the container could contain any arbitrary Xamarin.Forms views, for example a layout with multiple views that would still render the normal way (or using their own custom renderers). The decoration would be the only thing that is platform specific.

How should I approach this? I could have a Content property on my container view, which would have the type View, and then somehow render that on each platform's renderer. But how do I take a View and render it in a platform specific way? A sample usage might be like this.

var foo = new Label { Text = "foo" };
var bar = new Label { Text = "bar" };

var box = new DecoratedBox { Content = new StackLayout { Children = { foo, bar } } };

Best Answer


  • SKallSKall USMember ✭✭✭✭

    How about putting the two views inside a RelativeLayout?

  • JakubArnold.8011JakubArnold.8011 CZMember ✭✭
    edited August 2014

    That would only work if the views are fixed size, no? What if the decoration is not only different color, but different shape, so that I can't "position" them the same way on both platforms, such as this

Sign In or Register to comment.