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

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

namespace Xamarin.PropertyEditing.Windows
{
	internal class MenuButton
		: Button
	{
		public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register (
			nameof(Header), typeof(object), typeof(MenuButton), new PropertyMetadata (default(object)));

		public object Header
		{
			get { return (object) GetValue (HeaderProperty); }
			set { SetValue (HeaderProperty, value); }
		}

		public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register (
			nameof(HeaderTemplate), typeof(DataTemplate), typeof(MenuButton), new PropertyMetadata (default(DataTemplate)));

		public DataTemplate HeaderTemplate
		{
			get { return (DataTemplate) GetValue (HeaderTemplateProperty); }
			set { SetValue (HeaderTemplateProperty, value); }
		}

		protected override void OnClick ()
		{
			base.OnClick ();

			if (ContextMenu != null)
				OpenMenu();
		}

		protected override void OnMouseDown (MouseButtonEventArgs e)
		{
			if (ContextMenu == null)
				return;

			OpenMenu ();
			e.Handled = true;

			base.OnMouseDown (e);
		}

		private void OpenMenu ()
		{
			ContextMenu.PlacementTarget = this;
			ContextMenu.Placement = PlacementMode.Bottom;
			ContextMenu.IsOpen = true;
		}
	}
}