I am trying to create a native UWP view from a Xamarin Forms view. Following the example from here, I managed to do it for Android and IOS.
More precisely, on IOS the conversion looks like this:
public static UIView ConvertFormsToNative(Xamarin.Forms.View view, CGRect size)
{
var renderer = RendererFactory.GetRenderer (view);
renderer.NativeView.Frame = size;
renderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
renderer.NativeView.ContentMode = UIViewContentMode.ScaleToFill;
renderer.Element.Layout (size.ToRectangle());
var nativeView = renderer.NativeView;
nativeView.SetNeedsLayout ();
return nativeView;
}
However, I need a similar approach for UWP.
Any help would be appreciated!
Bookmark this question. Show activity on this post. When I started my solution in VS Community 2019 it said that the Xamarin Forms Shell did not support UWP. I just upgraded VS to 16.9.
Create a new Xamarin. Start Visual Studio. Click File > New > Project to create a new project. In the new project dialog, select the Mobile App (Xamarin. Forms) template and click Next.
Ok, I've solved this by writing the following code for uwp:
internal static FrameworkElement ConvertFormsToNative(View view, Rectangle size)
{
var renderer = Platform.CreateRenderer(view);
view.Layout(size);
return renderer.ContainerElement;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With