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

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

namespace Xamarin.PropertyEditing.Windows
{
	[TemplatePart (Name = "launch", Type = typeof(ButtonBase))]
	internal class CollectionEditor
		: PropertyEditorControl
	{
		static CollectionEditor ()
		{
			DefaultStyleKeyProperty.OverrideMetadata (typeof(CollectionEditor), new FrameworkPropertyMetadata (typeof(CollectionEditor)));
		}

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

			if (!(GetTemplateChild ("launch") is ButtonBase button))
				throw new InvalidOperationException ("Missing 'launch' button in CollectionEditor template");

			var topLevel = this.FindPropertiesHost ();

			button.Click += (sender, args) => {
				var window = new CollectionEditorWindow (topLevel.Resources.MergedDictionaries) {
					DataContext = DataContext,
					Owner = Window.GetWindow (topLevel)
				};

				window.ShowDialog ();
			};
		}
	}
}