summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs
new file mode 100644
index 0000000..7cbabc1
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Renderers/FrameRenderer.cs
@@ -0,0 +1,57 @@
+´╗┐using System.ComponentModel;
+using System.Drawing;
+using AppKit;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ public class FrameRenderer : VisualElementRenderer<Frame>
+ {
+ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.NewElement != null)
+ SetupLayer();
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+
+ if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName ||
+ e.PropertyName == Xamarin.Forms.Frame.OutlineColorProperty.PropertyName ||
+ e.PropertyName == Xamarin.Forms.Frame.HasShadowProperty.PropertyName)
+ SetupLayer();
+ }
+
+ void SetupLayer()
+ {
+ Layer.CornerRadius = 5;
+ if (Element.BackgroundColor == Color.Default)
+ Layer.BackgroundColor = NSColor.White.CGColor;
+ else
+ Layer.BackgroundColor = Element.BackgroundColor.ToCGColor();
+
+ if (Element.HasShadow)
+ {
+ Layer.ShadowRadius = 5;
+ Layer.ShadowColor = NSColor.Black.CGColor;
+ Layer.ShadowOpacity = 0.8f;
+ Layer.ShadowOffset = new SizeF();
+ }
+ else
+ Layer.ShadowOpacity = 0;
+
+ if (Element.OutlineColor == Color.Default)
+ Layer.BorderColor = NSColor.Clear.CGColor;
+ else
+ {
+ Layer.BorderColor = Element.OutlineColor.ToCGColor();
+ Layer.BorderWidth = 1;
+ }
+
+ Layer.RasterizationScale = NSScreen.MainScreen.BackingScaleFactor;
+ Layer.ShouldRasterize = true;
+ }
+ }
+} \ No newline at end of file