-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit the previously filled words by clicking on them
- Loading branch information
1 parent
27f2770
commit 5257a80
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnTappedBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Reactive.Disposables; | ||
using System.Windows.Input; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class ExecuteCommandOnTappedBehavior : DisposingBehavior<Control> | ||
{ | ||
public static readonly StyledProperty<ICommand?> CommandProperty = | ||
AvaloniaProperty.Register<ExecuteCommandOnTappedBehavior, ICommand?>(nameof(Command)); | ||
|
||
public static readonly StyledProperty<object?> CommandParameterProperty = | ||
AvaloniaProperty.Register<ExecuteCommandOnTappedBehavior, object?>(nameof(CommandParameter)); | ||
|
||
public ICommand? Command | ||
{ | ||
get => GetValue(CommandProperty); | ||
set => SetValue(CommandProperty, value); | ||
} | ||
|
||
public object? CommandParameter | ||
{ | ||
get => GetValue(CommandParameterProperty); | ||
set => SetValue(CommandParameterProperty, value); | ||
} | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
Gestures.TappedEvent.AddClassHandler<InputElement>( | ||
(x, _) => | ||
{ | ||
if (Equals(x, AssociatedObject)) | ||
{ | ||
var parameter = CommandParameter; | ||
if (Command is { } cmd && cmd.CanExecute(parameter)) | ||
{ | ||
cmd.Execute(parameter); | ||
} | ||
} | ||
}, | ||
RoutingStrategies.Tunnel | RoutingStrategies.Bubble) | ||
.DisposeWith(disposables); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters