Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DynamicFillBox.cs « Custom « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a542b5d7a9874a85a0a979e26a95fc243aa115cd (plain)
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
62
using System;
using AppKit;

namespace Xamarin.PropertyEditing.Mac
{
	internal class DynamicFillBox
		: NSBox
	{
		public DynamicFillBox (IHostResourceProvider hostResources, string colorName)
		{
			if (hostResources == null)
				throw new ArgumentNullException (nameof (hostResources));

			BorderWidth = 0;
			BoxType = NSBoxType.NSBoxCustom;
			TranslatesAutoresizingMaskIntoConstraints = false;
			this.colorName = colorName;
			if (colorName == null)
				FillColor = NSColor.Clear;

			HostResourceProvider = hostResources;
		}

		public IHostResourceProvider HostResourceProvider
		{
			get { return this.hostResources; }
			set
			{
				this.hostResources = value;
				ViewDidChangeEffectiveAppearance ();
			}
		}

		public string FillColorName
		{
			get => this.colorName;
			set
			{
				this.colorName = value;
				if (value == null)
					FillColor = NSColor.Clear;

				ViewDidChangeEffectiveAppearance ();
			}
		}

		public override void ViewDidChangeEffectiveAppearance ()
		{
			if (this.colorName == null)
				return;

			NSColor color = this.hostResources.GetNamedColor (this.colorName);
			if (color == null)
				return;

			FillColor = color;
		}

		private IHostResourceProvider hostResources;
		private string colorName;
	}
}