|
|
|
@ -4,6 +4,7 @@ |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Windows.Input; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Rendering; |
|
|
|
@ -41,8 +42,9 @@ namespace Avalonia.Controls |
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="Command"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<ICommand> CommandProperty = |
|
|
|
AvaloniaProperty.Register<Button, ICommand>(nameof(Command)); |
|
|
|
public static readonly DirectProperty<Button, ICommand> CommandProperty = |
|
|
|
AvaloniaProperty.RegisterDirect<Button, ICommand>(nameof(Command), |
|
|
|
button => button.Command, (button, command) => button.Command = command, enableDataValidation: true); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="HotKey"/> property.
|
|
|
|
@ -68,6 +70,8 @@ namespace Avalonia.Controls |
|
|
|
public static readonly RoutedEvent<RoutedEventArgs> ClickEvent = |
|
|
|
RoutedEvent.Register<Button, RoutedEventArgs>("Click", RoutingStrategies.Bubble); |
|
|
|
|
|
|
|
private ICommand _command; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes static members of the <see cref="Button"/> class.
|
|
|
|
/// </summary>
|
|
|
|
@ -102,8 +106,8 @@ namespace Avalonia.Controls |
|
|
|
/// </summary>
|
|
|
|
public ICommand Command |
|
|
|
{ |
|
|
|
get { return GetValue(CommandProperty); } |
|
|
|
set { SetValue(CommandProperty, value); } |
|
|
|
get { return _command; } |
|
|
|
set { SetAndRaise(CommandProperty, ref _command, value); } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -240,6 +244,15 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification status) |
|
|
|
{ |
|
|
|
base.UpdateDataValidation(property, status); |
|
|
|
if(property == CommandProperty) |
|
|
|
{ |
|
|
|
IsEnabled = status?.ErrorType != BindingErrorType.Error; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when the <see cref="Command"/> property changes.
|
|
|
|
/// </summary>
|
|
|
|
|