Use command instead of property to trigger close
MODIFY
WalletWasabi.Gui/Behaviors/CloseWindowBehavior.cs
WalletWasabi.Gui/Behaviors/CloseWindowBehavior.cs
@@ -3,37 +3,26 @@ using Avalonia.Controls;
using Avalonia.Xaml.Interactivity;
using ReactiveUI;
using System;
+using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
namespace WalletWasabi.Gui.Behaviors
{
- public class CloseWindowBehavior : Behavior<Window>
+ public class CloseWindowCommandBehavior : CommandBasedBehavior<Window>
{
- public static readonly StyledProperty<bool> CloseTriggerProperty =
- AvaloniaProperty.Register<Behavior, bool>(nameof(CloseTriggerProperty));
-
- public bool CloseTrigger
- {
- get => GetValue(CloseTriggerProperty);
- set => SetValue(CloseTriggerProperty, value);
- }
-
private CompositeDisposable Disposables { get; } = new CompositeDisposable();
protected override void OnAttached()
{
base.OnAttached();
- this.GetObservable(CloseTriggerProperty)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(closeTriggered =>
- {
- if (closeTriggered)
- {
- AssociatedObject.Close();
- }
- }).DisposeWith(Disposables);
+ this.GetObservable(CommandProperty)
+ .Where(cmd => cmd is { })
+ .Subscribe(cmd => ObservableExtensions.Subscribe(
+ (ReactiveCommand<Unit, Unit>)cmd,
+ _ => AssociatedObject.Close()))
+ .DisposeWith(Disposables);
}
protected override void OnDetaching()

MODIFY
WalletWasabi.Gui/CrashReport/ViewModels/CrashReportWindowViewModel.cs
WalletWasabi.Gui/CrashReport/ViewModels/CrashReportWindowViewModel.cs
@@ -11,8 +11,6 @@ namespace WalletWasabi.Gui.CrashReport.ViewModels
{
public class CrashReportWindowViewModel : ViewModelBase
{
- private bool _closeTrigger;
-
public CrashReportWindowViewModel()
{
var global = Locator.Current.GetService<Global>();
@@ -22,7 +20,7 @@ namespace WalletWasabi.Gui.CrashReport.ViewModels
OkCommand = ReactiveCommand.Create(() =>
{
- CloseTrigger = true;
+ // This command binded in xaml to close the window.
});
Observable
@@ -39,12 +37,6 @@ namespace WalletWasabi.Gui.CrashReport.ViewModels
public string Details => $"Wasabi has crashed. You can check the details here, open the log file, or report the crash to the support team.{Environment.NewLine}{Environment.NewLine}Please always consider your privacy before sharing any information!";
public string Message => CrashReporter?.SerializedException?.Message;
- public bool CloseTrigger
- {
- get => _closeTrigger;
- set => this.RaiseAndSetIfChanged(ref _closeTrigger, value);
- }
-
public ReactiveCommand<Unit, Unit> OpenLogCommand { get; }
public ReactiveCommand<Unit, Unit> OkCommand { get; }
}

MODIFY
WalletWasabi.Gui/CrashReport/Views/CrashReportWindow.xaml
WalletWasabi.Gui/CrashReport/Views/CrashReportWindow.xaml
Classes="ToolWindow"
CanResize="False">
<i:Interaction.Behaviors>
- <behaviors:CloseWindowBehavior CloseTrigger="{Binding CloseTrigger}" />
+ <behaviors:CloseWindowCommandBehavior Command="{Binding OkCommand}" />
</i:Interaction.Behaviors>
<DockPanel LastChildFill="True" Margin="25,0,25,25">
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="5" Margin="0,25,0,0">

Use command instead of property to trigger close