Create Native view WinRT from Xamarin Forms ContentView.

Hello sorry for my English.
I can make a render for xamarin view to native control Android and found very good.
Ex:
var r = Platform.GetRenderer(contenido);
if (r == null)
{
r = Platform.CreateRenderer(contenido);
Helper.AppDroidHelper.SetPlatform(contenido);
}

        var s = contenido.Measure(Forms.Context.Resources.DisplayMetrics.WidthPixels / Forms.Context.Resources.DisplayMetrics.Density, Forms.Context.Resources.DisplayMetrics.HeightPixels / Forms.Context.Resources.DisplayMetrics.Density);
        contenido.Layout(new Rectangle() { Width = s.Request.Width, Height = s.Request.Height });

        var width = (int)(s.Request.Width * Forms.Context.Resources.DisplayMetrics.Density);
        var height = (int)(s.Request.Height * Forms.Context.Resources.DisplayMetrics.Density);

        r.ViewGroup.LayoutParameters = new ViewGroup.LayoutParams(width, height);

        this.layout = new LinearLayout(Forms.Context) { LayoutParameters = new ViewGroup.LayoutParams(width, height) };
        this.layout.SetBackgroundColor(Android.Graphics.Color.Transparent);
        this.layout.AddView(r.ViewGroup);
        this.RequestWindowFeature((int)WindowFeatures.NoTitle);
        this.SetContentView(this.layout);

But in Windows Phone i cant't make work.
ContentDialog dialog = new ContentDialog();
dialog.content = viewXamarinForms.GetOrCreateRenderer().ContainerElement;

The render is create ok, but doesn't show any native control in the screen because the native controls doesn't have size.
I try calling Mesaure() and Layout() like in Android, but the view don't set Height and Width and when call the render doesn't show the native view.
Full class WinPhone proyect:
public class DialogWP: ContentDialog
{
public DialogWP(View xamarinFormsView view) : base()
{
var rec = view.Measure(Window.Current.Bounds.Width, Window.Current.Bounds.Height);
view.Layout(new Rectangle(0, 0, rec.Request.Width, Height = rec.Request.Height));
var r = view.GetOrCreateRenderer();
this.Content = r;
}

    public async void Show()
    {
        await this.ShowAsync();
    }

}

Tnks

Sign In or Register to comment.