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

CurrentColorEditorControl.cs « Xamarin.PropertyEditing.Windows - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d2090fabe692d9cb257806eacb0e5a1fd5c4ff1e (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
using System;
using System.Windows;
using System.Windows.Controls;
using Xamarin.PropertyEditing.Drawing;

namespace Xamarin.PropertyEditing.Windows
{
	internal class CurrentColorEditorControl : ColorEditorControlBase
	{
		public static readonly DependencyProperty InitialColorProperty =
			DependencyProperty.Register (
				nameof (InitialColor), typeof (CommonColor), typeof (CurrentColorEditorControl),
				new PropertyMetadata (new CommonColor (0, 0, 0)));

		public CommonColor InitialColor
		{
			get => (CommonColor)GetValue (InitialColorProperty);
			set => SetValue (InitialColorProperty, value);
		}

		public static readonly DependencyProperty LastColorProperty =
			DependencyProperty.Register (
				nameof (LastColor), typeof (CommonColor), typeof (CurrentColorEditorControl),
				new PropertyMetadata (new CommonColor (0, 0, 0)));

		public CommonColor LastColor
		{
			get => (CommonColor)GetValue (LastColorProperty);
			set => SetValue (LastColorProperty, value);
		}

		public override void OnApplyTemplate ()
		{
			base.OnApplyTemplate ();

			var initialColorButton = GetTemplateChild ("initialColorButton") as Button;

			if (initialColorButton == null)
				throw new InvalidOperationException ($"{nameof (CurrentColorEditorControl)} is missing a child Button named \"initialColorButton\"");

			initialColorButton.Click += (s, e) => {
				Color = InitialColor;
				RaiseEvent (new RoutedEventArgs (CommitCurrentColorEvent));
				RaiseEvent (new RoutedEventArgs (CommitHueEvent));
			};
		}
	}
}