-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.axaml.cs
55 lines (48 loc) · 1.88 KB
/
App.axaml.cs
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
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaDialogFirst.ViewModels;
using AvaloniaDialogFirst.Views;
using System;
using System.Reactive.Linq;
namespace AvaloniaDialogFirst
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// display dialog first
var dialog = new Dialog()
{
DataContext = new DialogViewModel(),
};
// .. and subscribe to its "Apply" button, which returns the dialog result
dialog.ViewModel!.ApplyCommand
/*.ObserveOn(RxApp.MainThreadScheduler).SubscribeOn(RxApp.MainThreadScheduler)*/
.Subscribe(result =>
{
Console.WriteLine("dialog apply button hit!");
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(result),
};
Console.WriteLine("new main window instantiated!");
// both of these lines are printed, but the window doesn't change
});
desktop.MainWindow = dialog;
// // replacing the MainWindow directly in here works (but is meaningless as I have no data for it)
// desktop.MainWindow = new MainWindow
// {
// DataContext = new MainWindowViewModel(null),
// };
}
base.OnFrameworkInitializationCompleted();
}
}
}