-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
203 lines (188 loc) · 5.8 KB
/
MainWindow.xaml.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TouristOrgAdmin.ViewModels;
using TouristOrgAdmin.Core;
using TouristOrgAdmin.Views;
using System.Globalization;
using TouristOrgAdmin.Controllers;
namespace TouristOrgAdmin
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static MainWindow instance;
private static BaseViewModel viewModel;
public BaseViewModel ViewModel
{
get => viewModel;
set
{
if (value != null)
{
viewModel = value;
viewModel.OnPropertyChanged("ViewModel");
}
}
}
public static void StaticNavigate(UserControl control, BaseViewModel viewModel)
{
GetInstance().Navigate(control, viewModel);
}
private void MainWindowInit()
{
InitializeComponent();
App.LanguageChanged += LanguageChanged;
CultureInfo currLang = App.Language;
MainCombo.Items.Clear();
foreach (var lang in App.Languages)
{
MenuItem menuLang = new MenuItem();
menuLang.Header = lang.DisplayName;
menuLang.Tag = lang;
menuLang.IsChecked = lang.Equals(currLang);
menuLang.Click += ChangeLanguageClick;
MainCombo.Items.Add(menuLang);
}
ViewModel = new TouristOrganizationViewModel();
try
{
if ((ViewModel as TouristOrganizationViewModel).DB.AdminAccount.Count() != 0)
{
ViewModel.ContentPath = LoginControl.GetInstance(ViewModel);
}
else ViewModel.ContentPath = RegisterControl.GetInstance(ViewModel);
}
catch (Exception)
{
}
DataContext = this;
}
private void ChangeLanguageClick(Object sender, EventArgs e)
{
MenuItem mi = sender as MenuItem;
if (mi != null)
{
CultureInfo lang = mi.Tag as CultureInfo;
if (lang != null)
{
App.Language = lang;
}
}
}
private void LanguageChanged(Object sender, EventArgs e)
{
CultureInfo currLang = App.Language;
//Отмечаем нужный пункт смены языка как выбранный язык
foreach (MenuItem i in MainCombo.Items)
{
CultureInfo ci = i.Tag as CultureInfo;
i.IsChecked = ci != null && ci.Equals(currLang);
}
try
{
((TouristOrganizationViewModel)ViewModel).ErrorText = "";
((ILanguages)ViewModel).LanguageChanged();
}
catch (Exception)
{
}
}
public MainWindow()
{
MainWindowInit();
instance = this;
}
public static MainWindow GetInstance()
{
if (instance == null)
{
instance = new MainWindow();
return instance;
}
return instance;
}
public void Navigate(UserControl control, BaseViewModel viewModel)
{
ViewModel = viewModel;
ViewModel.ContentPath = control;
usercontrol.Focus();
try
{
((TouristOrganizationViewModel)ViewModel).TempString = "";
((TouristOrganizationViewModel)ViewModel).ErrorText = "";
}
catch (Exception)
{
}
}
private void CloseButtonClick(object sender, RoutedEventArgs e)
{
Close();
}
private void SetButton_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void FullButton_Click(object sender, RoutedEventArgs e)
{
if (WindowState != WindowState.Maximized)
{
WindowState = WindowState.Maximized;
try
{
(ViewModel as TouristOrganizationViewModel).MaximumHeight = (int)(Height - Height * 0.3);
}
catch (Exception)
{
}
}
else
{
WindowState = WindowState.Normal;
try
{
(ViewModel as TouristOrganizationViewModel).MaximumHeight = 350;
}
catch (Exception)
{
}
}
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
DragMove();
}
}
private void Grid_MouseDown_1(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
DragMove();
}
}
private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
if (!MainCombo.IsDropDownOpen)
{
MainCombo.IsDropDownOpen = true;
}
else MainCombo.IsDropDownOpen = false;
}
}
}