-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRCommandPanel.cs
58 lines (50 loc) · 1.91 KB
/
RCommandPanel.cs
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
using System.Windows.Input;
using Windows.System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
namespace Ratio.UWP.Controls
{
[ContentProperty(Name = "Content")]
public sealed class RCommandPanel : ContentControl
{
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command", typeof(ICommand), typeof(RCommandPanel), new PropertyMetadata(default(ICommand)));
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
"CommandParameter", typeof(object), typeof(RCommandPanel), new PropertyMetadata(default(object)));
public object CommandParameter
{
get => (object) GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public ICommand Command
{
get => (ICommand) GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public bool MarkAsHandled { get; set; }
public RCommandPanel()
{
Background = new SolidColorBrush(Colors.Transparent);
MarkAsHandled = true;
}
protected override void OnTapped(TappedRoutedEventArgs e)
{
if (Command == null) return;
if (!Command.CanExecute(CommandParameter)) return;
Command.Execute(CommandParameter);
e.Handled = MarkAsHandled;
}
protected override void OnKeyUp(KeyRoutedEventArgs e)
{
if (e.Key != VirtualKey.Space && e.Key != VirtualKey.Enter) return;
if (Command == null) return;
if (!Command.CanExecute(CommandParameter)) return;
Command.Execute(CommandParameter);
e.Handled = MarkAsHandled;
}
}
}