0

I'm trying to render some controls myself in the compile time. Meaning that i'm trying to create for instance a Xamarin.Forms.Button and get it's native Windows.UI.Xaml.Control.Buttonimage (or FormsButton to be accurate)all in compile time.

I was trying to apply this on a ContentView so by applying this theory, this is the code to accomplish that:

var contentView = Element.Content;
var renderer = contentView.GetOrCreateRenderer();
var nativeControl = renderer.ContainerLayout;

By doing so i get a native UWP FrameworkElement with all the properties of the ContentView like the background and so on. However, i don't get the children rendered. That actually makes sense because basically you render just the ContentView. But i have no idea how to render all it's children. Hope that the solution applies to any XamarinForms control that has a Children (or a Content) property

Adham Ali
  • 81
  • 8
  • Do you means that you want to get the all the sub element of ContentView in native renderer? – Nico Zhu Aug 13 '18 at 07:42
  • Yes, I want to render the ContentView and all of it's children just like what XamarinForms does at runtime. – Adham Ali Aug 13 '18 at 10:10
  • Have you used [Visual Tree Helper](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.visualtreehelper) in uwp? – Nico Zhu Aug 13 '18 at 10:56
  • I'm not sure i fully understand that. An example would be useful. A XamarinForms example since i will be creating renderers for the 3 platforms – Adham Ali Aug 13 '18 at 12:42
  • The Visual Tree Helper is used to get the children element from their container. but it only available in uwp platform. – Nico Zhu Aug 14 '18 at 01:47
  • So is there any UWP solution? – Adham Ali Aug 14 '18 at 08:04
  • As far as I know it is only way. – Nico Zhu Aug 14 '18 at 08:11
  • But how would XamarinForms does it? You create the layout and start adding children they are rendererd at runtime for each platform. – Adham Ali Aug 14 '18 at 09:04
  • This is [Xamarin.Forms](https://github.com/xamarin/Xamarin.Forms) open source project, for adding children is realize via Layout Renderer. – Nico Zhu Aug 14 '18 at 09:38

0 Answers0