Hi All
I am creating a custom control for Xamarin Forms, and I have renderers for all platforms.
I am currently working on implementing the renderer for the Windows Phone platform.
On of the properties on my custom control is of type DataTemplate, so therefore I need to do 2 things:
1) Get an instance of the Xamarin Control as detailed in the DataTemplate
2) Get a Renderer to transform that Xamarin control into the platform specific version.
for 1) I have the following code (simplified)
var view = fab.ButtonContentTemplate.CreateContent() as VisualElement;
for 2) I have the following code (simplified)
var nativeElement = RendererFactory.GetRenderer(view).ContainerElement;
However, nativeElement isn't a System.Windows.Control.Grid, which is what i would have expected it to be as the DataTemplate's root item is a Xamarin.Forms.Grid - the type of nativeElement is Xamarin.Forms.Platform.WinPhone.ViewRenderer.
So then I looked at the object graph for nativeElement, and there is a property called 'Control'. So I guessed that if I cast the IVisualElementRenderer to ViewRenderer I can access the 'Control' property, but for a Grid, this is null.
However, if the root element of my DataTemplate is a Label (for instance), the 'Control' property in the above scenario is a Windows Phone TextBlock - which is what I would have expected.
Can someone shed some light on this for me. There seems to be no documentation on the Xamarin site for working with DataTemplates, so I'm currently just fumbling around in the dark, and if you intend to create Custom controls in Forms, it is likely that you will need to solve this scenario at some point.
Thanks in anticipation
Dean