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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
using System;
using System.Reflection;
using AppKit;
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using Xamarin.PropertyEditing.Mac.Controls;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal class CustomExpressionView : BasePopOverViewModelControl
{
private const string CustomExpressionPropertyString = "CustomExpression";
private const string PreviewCustomExpressionString = "PreviewCustomExpression";
private const string AutocompleteItemsString = "AutocompleteItems";
public AutoClosePopOver PopOver { get; internal set; }
public CustomExpressionView (IHostResourceProvider hostResources, PropertyViewModel viewModel)
: base (hostResources, viewModel, Properties.Resources.CustomExpression, "pe-custom-expression-32")
{
Frame = new CGRect (CGPoint.Empty, new CGSize (250, 80));
Type vmType = viewModel.GetType ();
PropertyInfo previewCustomExpressionPropertyInfo = vmType.GetProperty (PreviewCustomExpressionString);
previewCustomExpressionPropertyInfo.SetValue (viewModel, string.Empty);
PropertyInfo customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString);
var value = customExpressionPropertyInfo.GetValue (viewModel);
NSControl editorControl = null;
PropertyInfo customAutocompleteItemsPropertyInfo = vmType.GetProperty (AutocompleteItemsString);
if (customAutocompleteItemsPropertyInfo.GetValue (viewModel) is ObservableCollectionEx<string> values) {
if (values != null && values.Count > 0) {
editorControl = new AutocompleteComboBox (hostResources, viewModel, values, previewCustomExpressionPropertyInfo);
} else {
editorControl = new NSTextField ();
}
}
editorControl.TranslatesAutoresizingMaskIntoConstraints = false;
editorControl.StringValue = (string)value ?? string.Empty;
editorControl.Activated += (sender, e) => {
PopOver.CloseOnEnter = true;
customExpressionPropertyInfo.SetValue (viewModel, editorControl.StringValue);
};
AddSubview (editorControl);
this.AddConstraints (new[] {
NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f),
NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f),
NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -57f),
NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight),
});
}
}
}
|