maui-linux/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs

48 строки
931 B
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
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;
2016-03-22 23:02:25 +03:00
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_menuItem.Activate();
2016-03-22 23:02:25 +03:00
}
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();
}
}
}