-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
70 lines (60 loc) · 2.18 KB
/
MainWindowViewModel.cs
File metadata and controls
70 lines (60 loc) · 2.18 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
69
70
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Prism.Commands;
//using Prism.Services.Dialogs;
using Prism.Dialogs;
using SampleApp.Common;
using SampleApp.Views;
using MenuItem = SampleApp.Main.Models.MenuItem;
namespace SampleApp.ViewModels;
public class MainWindowViewModel : ViewModelBase
{
private readonly IDialogService _dialogService;
public MainWindowViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
}
/// <summary>Shutdown classic desktop application.</summary>
public DelegateCommand<Window> CmdMenuExitAppLifetime => new((Window win) =>
{
// NOTE:
// We configured the app as a Classic Desktop Lifetime
// `public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);`
if (Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
desktopLifetime.Shutdown();
}
else
{
System.Console.WriteLine("Shut down application issue..");
System.Diagnostics.Debugger.Break();
}
});
/// <summary>Close app by closing window.</summary>
public DelegateCommand<Window> CmdMenuExitWindow => new((Window win) =>
{
// Configuration:
// In the `.axml` set the window name ` x:Name="MainShellWindow"`
// and pass the Window in as a CommandParameter
//
// NOTE:
// This doesn't take into account other opened windows
// Ideally, you should check for other opened windows and close them all out.
//
// One method is to perform a Prism Event Notification to all the views to 'CloseWindow'
// and perform the same action below.
win?.Close();
});
public DelegateCommand<string> CmdShowDialog => new((string param) =>
{
var title = "Menu Item Clicked";
var messg = $"You clicked the {param} button";
_dialogService.ShowDialog(
nameof(MessageBoxView),
new DialogParameters($"title={title}&message={messg}"),
result => { });
});
public string Greeting => "Welcome to Avalonia!";
public ObservableCollection<MenuItem> MenuItems { get; } = new ObservableCollection<MenuItem>();
}