1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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, 80));
var customExpressionField = new NSTextField {
StringValue = string.Empty,
TranslatesAutoresizingMaskIntoConstraints = false,
};
this.vmType = viewModel.GetType ();
this.customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString);
var value = this.customExpressionPropertyInfo.GetValue (viewModel);
if (value != null)
customExpressionField.StringValue = (string)value;
customExpressionField.Activated += (sender, e) => {
this.customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue);
};
AddSubview (customExpressionField);
this.AddConstraints (new[] {
NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f),
NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f),
NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -57f),
NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight),
});
}
}
}
|