forked from CommunityToolkit/WindowsCommunityToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.Extensions.cs
More file actions
95 lines (83 loc) · 3.82 KB
/
Menu.Extensions.cs
File metadata and controls
95 lines (83 loc) · 3.82 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using Windows.UI.Xaml;
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// Menu Control defines a menu of choices for users to invoke.
/// </summary>
public partial class Menu
{
private const string InputGestureTextName = "InputGestureText";
private const string AllowTooltipName = "AllowTooltip";
/// <summary>
/// Sets the text describing an input gesture that will call the command tied to the specified item.
/// </summary>
public static readonly DependencyProperty InputGestureTextProperty = DependencyProperty.RegisterAttached(InputGestureTextName, typeof(string), typeof(FrameworkElement), new PropertyMetadata(null, InputGestureTextChanged));
private static void InputGestureTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var element = sender as FrameworkElement;
var inputGestureValue = element?.GetValue(InputGestureTextProperty).ToString();
if (string.IsNullOrEmpty(inputGestureValue))
{
return;
}
inputGestureValue = inputGestureValue.ToUpper();
if (MenuItemInputGestureCache.ContainsKey(inputGestureValue))
{
MenuItemInputGestureCache[inputGestureValue] = element;
return;
}
MenuItemInputGestureCache.Add(inputGestureValue.ToUpper(), element);
}
/// <summary>
/// Gets InputGestureText attached property
/// </summary>
/// <param name="obj">Target MenuFlyoutItem</param>
/// <returns>Input gesture text</returns>
public static string GetInputGestureText(FrameworkElement obj)
{
return (string)obj.GetValue(InputGestureTextProperty);
}
/// <summary>
/// Sets InputGestureText attached property
/// </summary>
/// <param name="obj">Target MenuFlyoutItem</param>
/// <param name="value">Input gesture text</param>
public static void SetInputGestureText(FrameworkElement obj, string value)
{
obj.SetValue(InputGestureTextProperty, value);
}
/// <summary>
/// Gets or sets a value indicating whether to allow tooltip on alt or not
/// </summary>
public static readonly DependencyProperty AllowTooltipProperty = DependencyProperty.RegisterAttached(AllowTooltipName, typeof(bool), typeof(Menu), new PropertyMetadata(false));
/// <summary>
/// Gets AllowTooltip attached property
/// </summary>
/// <param name="obj">Target Menu</param>
/// <returns>AllowTooltip</returns>
public static bool GetAllowTooltip(Menu obj)
{
return (bool)obj.GetValue(AllowTooltipProperty);
}
/// <summary>
/// Sets AllowTooltip attached property
/// </summary>
/// <param name="obj">Target Menu</param>
/// <param name="value">AllowTooltip</param>
public static void SetAllowTooltip(Menu obj, bool value)
{
obj.SetValue(AllowTooltipProperty, value);
}
}
}