diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs b/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs new file mode 100644 index 00000000..31574b44 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT/MenuItemCommand.cs @@ -0,0 +1,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(); + } + } +}
\ No newline at end of file |