Skip to content

Commit 68f3f01

Browse files
Add a close event for view models + cleanup
1 parent 95a1c93 commit 68f3f01

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

WatchOnlyBitcoinWallet/Services/WindowManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public Task ShowDialog(ViewModelBase vm)
3939
Title = vm.GetType().Name.Replace("ViewModel", ""),
4040
};
4141

42+
vm.CLoseEvent += (s, e) => win.Close();
43+
4244
var lf = (IClassicDesktopStyleApplicationLifetime?)Application.Current?.ApplicationLifetime;
4345
Debug.Assert(lf is not null);
4446
Debug.Assert(lf.MainWindow is not null);

WatchOnlyBitcoinWallet/ViewModels/ViewModelBase.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,42 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
55

6+
using System;
67
using WatchOnlyBitcoinWallet.MVVM;
78

89
namespace WatchOnlyBitcoinWallet.ViewModels
910
{
1011
public class ViewModelBase : InpcBase
1112
{
12-
/// <summary>
13-
/// Used for changing the visibility of error message TextBox.
14-
/// </summary>
13+
public event EventHandler? CLoseEvent;
14+
15+
public void RaiseCloseEvent() => CLoseEvent?.Invoke(this, EventArgs.Empty);
16+
17+
private bool _isErrVisible;
1518
public bool IsErrorMsgVisible
1619
{
17-
get => isErrorMsgVisible;
18-
private set => SetField(ref isErrorMsgVisible, value);
20+
get => _isErrVisible;
21+
private set => SetField(ref _isErrVisible, value);
1922
}
20-
private bool isErrorMsgVisible;
2123

22-
/// <summary>
23-
/// String containing all the errors.
24-
/// </summary>
24+
private string _errors = string.Empty;
2525
public string Errors
2626
{
27-
get => errors;
27+
get => _errors;
2828
set
2929
{
30-
if (SetField(ref errors, value))
30+
if (SetField(ref _errors, value))
3131
{
3232
IsErrorMsgVisible = !string.IsNullOrEmpty(value);
3333
}
3434
}
3535
}
36-
private string errors;
3736

38-
/// <summary>
39-
/// Status, showing current action being performed.
40-
/// </summary>
37+
private string _status = string.Empty;
4138
public string Status
4239
{
43-
get => status;
44-
set => SetField(ref status, value);
40+
get => _status;
41+
set => SetField(ref _status, value);
4542
}
46-
private string status;
47-
4843
}
4944
}

0 commit comments

Comments
 (0)