-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
68 lines (58 loc) · 1.8 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
68 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using MainCore.UI.ViewModels;
using MainCore.UI.ViewModels.UserControls;
using ReactiveMarbles.Extensions.Hosting.Wpf;
using ReactiveUI;
using System;
using System.ComponentModel;
using System.Reactive.Disposables.Fluent;
using System.Reactive.Linq;
using System.Windows;
namespace WPFUI.Views
{
public class MainWindowBase : ReactiveWindow<MainViewModel>
{
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MainWindowBase, IWpfShell
{
private bool _canClose = false;
private bool _isClosing = false;
private bool _isLoaded = false;
public MainWindow(MainViewModel mainViewModel, WaitingOverlayViewModel waitingOverlayViewModel)
{
InitializeComponent();
Loaded += OnLoaded;
Closing += OnClosing;
ViewModel = mainViewModel;
WaitingOverlay.ViewModel = waitingOverlayViewModel;
this.WhenActivated(d =>
{
this.Bind(ViewModel, vm => vm.MainLayoutViewModel, v => v.MainLayout.Content).DisposeWith(d);
});
}
private async void OnLoaded(object sender, RoutedEventArgs e)
{
if (_isLoaded) return;
_isLoaded = false;
await ViewModel.LoadCommand.Execute();
_isLoaded = true;
}
private async void OnClosing(object sender, CancelEventArgs e)
{
if (!_isLoaded)
{
e.Cancel = true;
return;
}
if (_canClose) return;
e.Cancel = true;
if (_isClosing) return;
_isClosing = true;
await ViewModel.UnloadCommand.Execute();
_canClose = true;
Close();
}
}
}