-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainVM.cs
102 lines (93 loc) · 3.12 KB
/
MainVM.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
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
using QuikSharp;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Linq;
namespace QUIKSharpTEST2
{
//https://www.cyberforum.ru/wpf-silverlight/thread3167641.html
internal class MainVM : ViewModelBase
{
//MainWindow wnd = (MainWindow)App.Current.MainWindow;
private ObservableCollection<Tool> _ListTools = [];
private Tool _SelectedTool;
public ObservableCollection<Tool> ListTools
{
get => _ListTools;
set => SetField(ref _ListTools, value);
}
#region SelectedItem
public Tool SelectedTool
{
get => _SelectedTool;
set => SetField(ref _SelectedTool, value);
}
#endregion
// команда удаления
public void Remove()
{
if (!SelectedTool.Isactiv)
{
SelectedTool.Log(SelectedTool.Name + " - Удаление и чистка");
SelectedTool.KillOperationOrders();
SelectedTool.Unsubscribe();
ListTools.Remove(SelectedTool);
}
else
{
SelectedTool.Log("Удаление и чистка" + SelectedTool.Name + " НЕ ВОЗМОЖНА при включенной стратегии");
}
}
public void KillOperationOrders()
{
SelectedTool.Isactiv = false;
// _SelectedTool.KillOperationOrders();
}
public void ClosPositions()
{
//SelectedTool.Isactiv = false;
if (!SelectedTool.Isactiv)
{
SelectedTool.CloseAllpositions();
}
else
{
SelectedTool.Log("CloseAllpositions" + SelectedTool.Name + " НЕ ВОЗМОЖНА при включенной стратегии");
}
}
public class EnumToArrayConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rr = Enum.GetValues(value as Type);
return rr;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null; // I don't care about this
}
}
}
internal class RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
: ICommand
{
event EventHandler ICommand.CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
bool ICommand.CanExecute(object parameter)
{
return canExecute == null || canExecute(parameter);
}
void ICommand.Execute(object parameter)
{
execute(parameter);
}
}
}