forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuItemCommand.cs
42 lines (35 loc) · 861 Bytes
/
MenuItemCommand.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
using System;
using System.ComponentModel;
using System.Windows.Input;
namespace Xamarin.Forms.Platform.UWP
{
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();
}
}
}