summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs
new file mode 100644
index 0000000..d4e9ad0
--- /dev/null
+++ b/Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs
@@ -0,0 +1,39 @@
+´╗┐using System.ComponentModel;
+using AppKit;
+
+namespace Xamarin.Forms.Platform.MacOS
+{
+ public class BoxViewRenderer : ViewRenderer<BoxView, NSView>
+ {
+ protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
+ {
+ if (e.NewElement != null)
+ {
+ if (Control == null)
+ {
+ SetNativeControl(new NSView());
+ }
+ SetBackgroundColor(Element.Color);
+ }
+
+ base.OnElementChanged(e);
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+ if (e.PropertyName == BoxView.ColorProperty.PropertyName)
+ SetBackgroundColor(Element.BackgroundColor);
+ else if (e.PropertyName == VisualElement.IsVisibleProperty.PropertyName && Element.IsVisible)
+ SetNeedsDisplayInRect(Bounds);
+ }
+
+ protected override void SetBackgroundColor(Color color)
+ {
+ if (Element == null || Control == null)
+ return;
+ Control.WantsLayer = true;
+ Control.Layer.BackgroundColor = color.ToCGColor();
+ }
+ }
+} \ No newline at end of file