-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainViewModel.cs
More file actions
170 lines (136 loc) · 3.83 KB
/
MainViewModel.cs
File metadata and controls
170 lines (136 loc) · 3.83 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using MyApp.Common;
using MyApp.Core;
using MyApp.Services;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
namespace MyApp.Presentation.ViewModels;
public partial class MainViewModel : INotifyPropertyChanged
{
private readonly ISelectService _selectService;
public MainViewModel(ISelectService selectService)
{
_selectService = selectService ?? throw new ArgumentNullException(nameof(selectService));
OkCommand = new RelayCommand<Window>(ExecuteOkCommand, CanExecuteOkCommand);
CancelCommand = new RelayCommand<Window>(ExecuteCancelCommand);
SelectCommand = new RelayCommand<object>(ExecuteSelectCommand);
_statusMessage = "Started";
SelectOptions = new SelectOptions
{
SelectLines = true,
SelectPolyLines = true,
SelectArcs = true
};
}
private SelectOptions _selectOptions;
public SelectOptions SelectOptions
{
get => _selectOptions;
set
{
_selectOptions = value;
OnPropertyChanged();
}
}
// --- Properties --------------------------------------------------------
#region Title
private string _title = "Total Length 1.0";
public string Title
{
get
{
#if DEBUG
return _title + $" - [{Version}]";
#else
return _title;
#endif
}
set
{
_title = value;
OnPropertyChanged();
}
}
public string Version
{
get => DateTime.Now.ToString("HH-mm-ss");
}
#endregion
#region Status
private string _statusMessage;
public string StatusMessage
{
get => _statusMessage;
set
{
_statusMessage = value;
OnPropertyChanged();
}
}
#endregion
// --- Commands ----------------------------------------------------------
#region Select Command
public ICommand SelectCommand { get; }
private int _selectedObjectCount;
public int SelectedObjectCount
{
get => _selectedObjectCount;
set
{
_selectedObjectCount = value;
OnPropertyChanged();
}
}
private double _totalLength;
public double TotalLength
{
get => _totalLength;
set
{
_totalLength = value;
OnPropertyChanged();
}
}
private void ExecuteSelectCommand(object parameter)
{
var (count, length, message) = _selectService.SelectObjects(SelectOptions);
SelectedObjectCount = count;
TotalLength = Math.Round(length,2);
StatusMessage = message;
}
#endregion
#region OK Command
public ICommand OkCommand { get; }
private void ExecuteOkCommand(Window window)
{
// Add your custom logic here
StatusMessage = "OK Command Executed!";
MessageBox.Show("OK button clicked. The window will now close.");
// Close the window
window?.Close();
}
private bool CanExecuteOkCommand(Window window)
{
// Add any condition to enable or disable the OK button
return true; // Always enabled for now
}
#endregion
#region Cancel Command
public ICommand CancelCommand { get; }
private void ExecuteCancelCommand(Window window)
{
// Close the window
window?.Close();
}
#endregion
// --- Events ------------------------------------------------------------
#region Property Changed Event
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}