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

TypeEditorControl.cs « Xamarin.PropertyEditing.Windows - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4fd357502fb14d58accb45ce24fd033e433203dd (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
using System.Threading.Tasks;
using System.Windows;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Windows
{
	internal class TypeEditorControl
		: PropertyEditorControl
	{
		static TypeEditorControl ()
		{
			DefaultStyleKeyProperty.OverrideMetadata (typeof (TypeEditorControl), new FrameworkPropertyMetadata (typeof (TypeEditorControl)));
		}

		public TypeEditorControl ()
		{
			DataContextChanged += OnDataContextChanged;
		}

		private TypePropertyViewModel vm;

		private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e)
		{
			if (this.vm != null)
				this.vm.TypeRequested -= OnTypeRequested;

			this.vm = e.NewValue as TypePropertyViewModel;
			if (this.vm != null)
				this.vm.TypeRequested += OnTypeRequested;
		}

		private void OnTypeRequested (object sender, TypeRequestedEventArgs e)
		{
			var vsender = (TypePropertyViewModel)sender;

			var panel = this.FindPropertiesHost ();

			ITypeInfo type = TypeSelectorWindow.RequestType (panel, vsender.AssignableTypes);
			e.SelectedType = Task.FromResult (type);
		}
	}
}