|
|
|
@ -10,6 +10,7 @@ namespace Avalonia.Controls |
|
|
|
private string _header; |
|
|
|
private KeyGesture _gesture; |
|
|
|
private bool _enabled = true; |
|
|
|
private ICommand _command; |
|
|
|
|
|
|
|
private NativeMenu _menu; |
|
|
|
|
|
|
|
@ -55,13 +56,7 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly DirectProperty<NativeMenuItem, NativeMenu> MenuProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, NativeMenu>(nameof(Menu), o => o._menu, |
|
|
|
(o, v) => |
|
|
|
{ |
|
|
|
if (v.Parent != null && v.Parent != o) |
|
|
|
throw new InvalidOperationException("NativeMenu already has a parent"); |
|
|
|
o._menu = v; |
|
|
|
}); |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, NativeMenu>(nameof(Menu), o => o.Menu, (o, v) => o.Menu = v); |
|
|
|
|
|
|
|
public NativeMenu Menu |
|
|
|
{ |
|
|
|
@ -75,38 +70,26 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly DirectProperty<NativeMenuItem, string> HeaderProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, string>(nameof(Header), o => o._header, (o, v) => o._header = v); |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, string>(nameof(Header), o => o.Header, (o, v) => o.Header = v); |
|
|
|
|
|
|
|
public string Header |
|
|
|
{ |
|
|
|
get => GetValue(HeaderProperty); |
|
|
|
set => SetValue(HeaderProperty, value); |
|
|
|
get => _header; |
|
|
|
set => SetAndRaise(HeaderProperty, ref _header, value); |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly DirectProperty<NativeMenuItem, KeyGesture> GestureProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, KeyGesture>(nameof(Gesture), o => o._gesture, (o, v) => o._gesture = v); |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, KeyGesture>(nameof(Gesture), o => o.Gesture, (o, v) => o.Gesture = v); |
|
|
|
|
|
|
|
public KeyGesture Gesture |
|
|
|
{ |
|
|
|
get => GetValue(GestureProperty); |
|
|
|
set => SetValue(GestureProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
private ICommand _command; |
|
|
|
get => _gesture; |
|
|
|
set => SetAndRaise(GestureProperty, ref _gesture, value); |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly DirectProperty<NativeMenuItem, ICommand> CommandProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, ICommand>(nameof(Command), |
|
|
|
o => o._command, (o, v) => |
|
|
|
{ |
|
|
|
if (o._command != null) |
|
|
|
WeakSubscriptionManager.Unsubscribe(o._command, |
|
|
|
nameof(ICommand.CanExecuteChanged), o._canExecuteChangedSubscriber); |
|
|
|
o._command = v; |
|
|
|
if (o._command != null) |
|
|
|
WeakSubscriptionManager.Subscribe(o._command, |
|
|
|
nameof(ICommand.CanExecuteChanged), o._canExecuteChangedSubscriber); |
|
|
|
o.CanExecuteChanged(); |
|
|
|
}); |
|
|
|
o => o.Command, (o, v) => o.Command = v); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="CommandParameter"/> property.
|
|
|
|
@ -115,13 +98,12 @@ namespace Avalonia.Controls |
|
|
|
Button.CommandParameterProperty.AddOwner<MenuItem>(); |
|
|
|
|
|
|
|
public static readonly DirectProperty<NativeMenuItem, bool> EnabledProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, bool>(nameof(Enabled), o => o._enabled, |
|
|
|
(o, v) => o._enabled = v, true); |
|
|
|
AvaloniaProperty.RegisterDirect<NativeMenuItem, bool>(nameof(Enabled), o => o.Enabled, (o, v) => o.Enabled = v, true); |
|
|
|
|
|
|
|
public bool Enabled |
|
|
|
{ |
|
|
|
get => GetValue(EnabledProperty); |
|
|
|
set => SetValue(EnabledProperty, value); |
|
|
|
get => _enabled; |
|
|
|
set => SetAndRaise(EnabledProperty, ref _enabled, value); |
|
|
|
} |
|
|
|
|
|
|
|
void CanExecuteChanged() |
|
|
|
@ -133,8 +115,21 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
public ICommand Command |
|
|
|
{ |
|
|
|
get => GetValue(CommandProperty); |
|
|
|
set => SetValue(CommandProperty, value); |
|
|
|
get => _command; |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_command != null) |
|
|
|
WeakSubscriptionManager.Unsubscribe(_command, |
|
|
|
nameof(ICommand.CanExecuteChanged), _canExecuteChangedSubscriber); |
|
|
|
|
|
|
|
SetAndRaise(CommandProperty, ref _command, value); |
|
|
|
|
|
|
|
if (_command != null) |
|
|
|
WeakSubscriptionManager.Subscribe(_command, |
|
|
|
nameof(ICommand.CanExecuteChanged), _canExecuteChangedSubscriber); |
|
|
|
|
|
|
|
CanExecuteChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|