summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs b/Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs
new file mode 100644
index 00000000..0e669774
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/NativeViewWrapperRenderer.cs
@@ -0,0 +1,74 @@
+using Windows.UI.Xaml;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ public class NativeViewWrapperRenderer : ViewRenderer<NativeViewWrapper, FrameworkElement>
+ {
+ public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
+ {
+ if (Element?.GetDesiredSizeDelegate == null)
+ {
+ return base.GetDesiredSize(widthConstraint, heightConstraint);
+ }
+
+ // The user has specified a different implementation of GetDesiredSize
+ SizeRequest? result = Element.GetDesiredSizeDelegate(this, widthConstraint, heightConstraint);
+
+ // If the delegate returns a SizeRequest, we use it;
+ // if it returns null, fall back to the default implementation
+ return result ?? base.GetDesiredSize(widthConstraint, heightConstraint);
+ }
+
+ protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize)
+ {
+ if (Element?.ArrangeOverrideDelegate == null)
+ {
+ return base.ArrangeOverride(finalSize);
+ }
+
+ // The user has specified a different implementation of ArrangeOverride
+ Windows.Foundation.Size? result = Element.ArrangeOverrideDelegate(this, finalSize);
+
+ // If the delegate returns a Size, we use it;
+ // if it returns null, fall back to the default implementation
+ return result ?? base.ArrangeOverride(finalSize);
+ }
+
+ protected Windows.Foundation.Size MeasureOverride()
+ {
+ return MeasureOverride(new Windows.Foundation.Size());
+ }
+
+ protected override Windows.Foundation.Size MeasureOverride(Windows.Foundation.Size availableSize)
+ {
+ if (Element?.MeasureOverrideDelegate == null)
+ {
+ return base.MeasureOverride(availableSize);
+ }
+
+ // The user has specified a different implementation of MeasureOverride
+ Windows.Foundation.Size? result = Element.MeasureOverrideDelegate(this, availableSize);
+
+ // If the delegate returns a Size, we use it;
+ // if it returns null, fall back to the default implementation
+ return result ?? base.MeasureOverride(availableSize);
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<NativeViewWrapper> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.OldElement == null)
+ {
+ SetNativeControl(Element.NativeElement);
+ Control.LayoutUpdated += (sender, args) => { Element?.InvalidateMeasure(InvalidationTrigger.MeasureChanged); };
+ }
+ }
+ }
+} \ No newline at end of file