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

CollectionEditorWindow.xaml.cs « Xamarin.PropertyEditing.Windows - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1854c200b2038b33ef99c763ddec6cfb3bef9e69 (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Windows
{
	internal partial class CollectionEditorWindow
		: WindowEx, IPropertiesHost
	{
		public CollectionEditorWindow (IEnumerable<ResourceDictionary> mergedResources)
		{
			InitializeComponent ();
			Resources.MergedDictionaries.AddItems (mergedResources);
			DataContextChanged += OnDataContextChanged;
		}

		protected override void OnClosing (CancelEventArgs e)
		{
			if (DataContext is CollectionPropertyViewModel vm) {
				if (!DialogResult.HasValue || !DialogResult.Value)
					vm.CancelCommand.Execute (null);

				vm.TypeRequested -= OnTypeRequested;
			}

			base.OnClosing (e);
		}

		private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e)
		{
			if (e.OldValue is CollectionPropertyViewModel oldVm)
				oldVm.TypeRequested -= OnTypeRequested;

			if (e.NewValue is CollectionPropertyViewModel vm)
				vm.TypeRequested += OnTypeRequested;
		}

		private void OnTypeRequested (object sender, TypeRequestedEventArgs args)
		{
			args.SelectedType = Task.FromResult (TypeSelectorWindow.RequestType (this, ((CollectionPropertyViewModel)DataContext).AssignableTypes));
		}

		private void OnOkClick (object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		private void OnCancelClick (object sender, RoutedEventArgs e)
		{
			DialogResult = false;
		}
	}
}