blob: 31574b446f178e7079078a4cc3e1a1c2dc769c6d (
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
|
using System;
using System.ComponentModel;
using System.Windows.Input;
#if WINDOWS_UWP
namespace Xamarin.Forms.Platform.UWP
#else
namespace Xamarin.Forms.Platform.WinRT
#endif
{
internal class MenuItemCommand : ICommand
{
readonly MenuItem _menuItem;
public MenuItemCommand(MenuItem item)
{
_menuItem = item;
_menuItem.PropertyChanged += OnElementPropertyChanged;
}
public virtual bool CanExecute(object parameter)
{
return _menuItem.IsEnabled;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_menuItem.Activate();
}
void OnCanExecuteChanged()
{
EventHandler changed = CanExecuteChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
OnCanExecuteChanged();
}
}
}
|