2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Windows.Input;
6 namespace Tizen.NUI.Binding
9 internal class MenuItem : BaseMenuItem, IMenuItemController
11 public static readonly BindableProperty AcceleratorProperty = BindableProperty.CreateAttached(nameof(Accelerator), typeof(Accelerator), typeof(MenuItem), null);
13 public static Accelerator GetAccelerator(BindableObject bindable) => (Accelerator)bindable.GetValue(AcceleratorProperty);
15 public static void SetAccelerator(BindableObject bindable, Accelerator value) => bindable.SetValue(AcceleratorProperty, value);
17 public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(MenuItem), null);
19 public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(MenuItem), null,
20 propertyChanging: (bo, o, n) => ((MenuItem)bo).OnCommandChanging(), propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandChanged());
22 public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(MenuItem), null,
23 propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandParameterChanged());
25 public static readonly BindableProperty IsDestructiveProperty = BindableProperty.Create("IsDestructive", typeof(bool), typeof(MenuItem), false);
27 public static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(MenuItem), default(FileImageSource));
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), typeof(ToolbarItem), true);
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public string IsEnabledPropertyName
37 return IsEnabledProperty.PropertyName;
41 public ICommand Command
43 get { return (ICommand)GetValue(CommandProperty); }
44 set { SetValue(CommandProperty, value); }
47 public object CommandParameter
49 get { return GetValue(CommandParameterProperty); }
50 set { SetValue(CommandParameterProperty, value); }
53 public FileImageSource Icon
55 get { return (FileImageSource)GetValue(IconProperty); }
56 set { SetValue(IconProperty, value); }
59 public bool IsDestructive
61 get { return (bool)GetValue(IsDestructiveProperty); }
62 set { SetValue(IsDestructiveProperty, value); }
67 get { return (string)GetValue(TextProperty); }
68 set { SetValue(TextProperty, value); }
71 [EditorBrowsable(EditorBrowsableState.Never)]
74 get { return (bool)GetValue(IsEnabledProperty); }
75 set { SetValue(IsEnabledProperty, value); }
80 set { SetValueCore(IsEnabledProperty, value); }
83 public event EventHandler Clicked;
85 protected virtual void OnClicked()
86 => Clicked?.Invoke(this, EventArgs.Empty);
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public void Activate()
94 Command.Execute(CommandParameter);
100 void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
102 IsEnabledCore = Command.CanExecute(CommandParameter);
105 void OnCommandChanged()
109 IsEnabledCore = true;
113 IsEnabledCore = Command.CanExecute(CommandParameter);
115 Command.CanExecuteChanged += OnCommandCanExecuteChanged;
118 void OnCommandChanging()
123 Command.CanExecuteChanged -= OnCommandCanExecuteChanged;
126 void OnCommandParameterChanged()
131 IsEnabledCore = Command.CanExecute(CommandParameter);