From ead73805bd3b147aa96f305ded0fdf35dcc66177 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Wed, 14 Feb 2018 16:30:31 +0000 Subject: [Mac] Initial CustomExpression Implementation. --- .../Controls/CustomExpressionView.cs | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs (limited to 'Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs') diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs new file mode 100644 index 0000000..17be2bc --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -0,0 +1,46 @@ +using System; +using System.Reflection; +using AppKit; +using CoreGraphics; +using Foundation; +using ObjCRuntime; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class CustomExpressionView : BasePopOverViewModelControl + { + Type vmType; + const string CustomExpressionPropertyString = "CustomExpression"; + PropertyInfo customExpressionPropertyInfo; + + public CustomExpressionView (PropertyViewModel viewModel) : base (viewModel, Properties.Resources.CustomExpression, "custom-expression-32") + { + Frame = new CGRect (CGPoint.Empty, new CGSize (250, 60)); + + var customExpressionField = new NSTextField { + StringValue = string.Empty, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + vmType = viewModel.GetType (); + customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); + var value = customExpressionPropertyInfo.GetValue (viewModel); + if (value != null) + customExpressionField.StringValue = (string)value; + + customExpressionField.Activated += (sender, e) => { + customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue); + }; + + AddSubview (customExpressionField); + + this.DoConstraints (new[] { + customExpressionField.ConstraintTo (this, (s, c) => s.Top == c.Top + 30), + customExpressionField.ConstraintTo (this, (s, c) => s.Left == c.Left + 30), + customExpressionField.ConstraintTo (this, (s, c) => s.Width == c.Width - 37), + customExpressionField.ConstraintTo (this, (s, c) => s.Height == 24), + }); + } + } +} -- cgit v1.2.3