|
|
@ -1,11 +1,9 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Diagnostics; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Windows.Input; |
|
|
using System.Windows.Input; |
|
|
using Avalonia.Automation.Peers; |
|
|
using Avalonia.Automation.Peers; |
|
|
using Avalonia.Controls.Metadata; |
|
|
using Avalonia.Controls.Metadata; |
|
|
using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Templates; |
|
|
|
|
|
using Avalonia.Data; |
|
|
using Avalonia.Data; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Interactivity; |
|
|
@ -48,9 +46,8 @@ namespace Avalonia.Controls |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Command"/> property.
|
|
|
/// Defines the <see cref="Command"/> property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static readonly DirectProperty<Button, ICommand?> CommandProperty = |
|
|
public static readonly StyledProperty<ICommand?> CommandProperty = |
|
|
AvaloniaProperty.RegisterDirect<Button, ICommand?>(nameof(Command), |
|
|
AvaloniaProperty.Register<Button, ICommand?>(nameof(Command), enableDataValidation: true); |
|
|
button => button.Command, (button, command) => button.Command = command, enableDataValidation: true); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="HotKey"/> property.
|
|
|
/// Defines the <see cref="HotKey"/> property.
|
|
|
@ -85,8 +82,8 @@ namespace Avalonia.Controls |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="IsPressed"/> property.
|
|
|
/// Defines the <see cref="IsPressed"/> property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static readonly StyledProperty<bool> IsPressedProperty = |
|
|
public static readonly DirectProperty<Button, bool> IsPressedProperty = |
|
|
AvaloniaProperty.Register<Button, bool>(nameof(IsPressed)); |
|
|
AvaloniaProperty.RegisterDirect<Button, bool>(nameof(IsPressed), b => b.IsPressed); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Flyout"/> property
|
|
|
/// Defines the <see cref="Flyout"/> property
|
|
|
@ -94,10 +91,10 @@ namespace Avalonia.Controls |
|
|
public static readonly StyledProperty<FlyoutBase?> FlyoutProperty = |
|
|
public static readonly StyledProperty<FlyoutBase?> FlyoutProperty = |
|
|
AvaloniaProperty.Register<Button, FlyoutBase?>(nameof(Flyout)); |
|
|
AvaloniaProperty.Register<Button, FlyoutBase?>(nameof(Flyout)); |
|
|
|
|
|
|
|
|
private ICommand? _command; |
|
|
|
|
|
private bool _commandCanExecute = true; |
|
|
private bool _commandCanExecute = true; |
|
|
private KeyGesture? _hotkey; |
|
|
private KeyGesture? _hotkey; |
|
|
private bool _isFlyoutOpen = false; |
|
|
private bool _isFlyoutOpen = false; |
|
|
|
|
|
private bool _isPressed = false; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Initializes static members of the <see cref="Button"/> class.
|
|
|
/// Initializes static members of the <see cref="Button"/> class.
|
|
|
@ -138,8 +135,8 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public ICommand? Command |
|
|
public ICommand? Command |
|
|
{ |
|
|
{ |
|
|
get => _command; |
|
|
get => GetValue(CommandProperty); |
|
|
set => SetAndRaise(CommandProperty, ref _command, value); |
|
|
set => SetValue(CommandProperty, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -185,8 +182,8 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public bool IsPressed |
|
|
public bool IsPressed |
|
|
{ |
|
|
{ |
|
|
get => GetValue(IsPressedProperty); |
|
|
get => _isPressed; |
|
|
private set => SetValue(IsPressedProperty, value); |
|
|
private set => SetAndRaise(IsPressedProperty, ref _isPressed, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -248,7 +245,7 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
if (_hotkey != null) // Control attached again, set Hotkey to create a hotkey manager for this control
|
|
|
if (_hotkey != null) // Control attached again, set Hotkey to create a hotkey manager for this control
|
|
|
{ |
|
|
{ |
|
|
HotKey = _hotkey; |
|
|
SetCurrentValue(HotKeyProperty, _hotkey); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
base.OnAttachedToLogicalTree(e); |
|
|
base.OnAttachedToLogicalTree(e); |
|
|
@ -267,7 +264,7 @@ namespace Avalonia.Controls |
|
|
if (HotKey != null) |
|
|
if (HotKey != null) |
|
|
{ |
|
|
{ |
|
|
_hotkey = HotKey; |
|
|
_hotkey = HotKey; |
|
|
HotKey = null; |
|
|
SetCurrentValue(HotKeyProperty, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
base.OnDetachedFromLogicalTree(e); |
|
|
base.OnDetachedFromLogicalTree(e); |
|
|
@ -291,17 +288,17 @@ namespace Avalonia.Controls |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case Key.Space: |
|
|
case Key.Space: |
|
|
{ |
|
|
|
|
|
if (ClickMode == ClickMode.Press) |
|
|
|
|
|
{ |
|
|
{ |
|
|
OnClick(); |
|
|
if (ClickMode == ClickMode.Press) |
|
|
|
|
|
{ |
|
|
|
|
|
OnClick(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IsPressed = true; |
|
|
|
|
|
e.Handled = true; |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IsPressed = true; |
|
|
|
|
|
e.Handled = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case Key.Escape when Flyout != null: |
|
|
case Key.Escape when Flyout != null: |
|
|
// If Flyout doesn't have focusable content, close the flyout here
|
|
|
// If Flyout doesn't have focusable content, close the flyout here
|
|
|
CloseFlyout(); |
|
|
CloseFlyout(); |
|
|
@ -592,7 +589,7 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
flyout.Opened -= Flyout_Opened; |
|
|
flyout.Opened -= Flyout_Opened; |
|
|
flyout.Closed -= Flyout_Closed; |
|
|
flyout.Closed -= Flyout_Closed; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -671,7 +668,7 @@ namespace Avalonia.Controls |
|
|
void ICommandSource.CanExecuteChanged(object sender, EventArgs e) => this.CanExecuteChanged(sender, e); |
|
|
void ICommandSource.CanExecuteChanged(object sender, EventArgs e) => this.CanExecuteChanged(sender, e); |
|
|
|
|
|
|
|
|
void IClickableControl.RaiseClick() => OnClick(); |
|
|
void IClickableControl.RaiseClick() => OnClick(); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Event handler for when the button's flyout is opened.
|
|
|
/// Event handler for when the button's flyout is opened.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
|