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
using MultiLayout;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
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 Unity;
using UnityConfigurationTree;
using LoadingProgress = MultiLayout.LoadingProgress;
namespace MultiLayout
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
IUnityContainer container;
LoadingProgress lp;
FlyLayoutManager manager;
WdMainVm viewModel;
NavigationService NavigationService => frame.NavigationService;
public MainWindow()
{
InitializeComponent();
viewModel = new WdMainVm();
this.DataContext = viewModel;//为了隐藏报警条
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//---------------------------------------------------------
//转到进度条页面
lp = new LoadingProgress();
PgLoading p = new PgLoading();
p.DataContext = lp;
NavigationService.Navigate(p);
await Task.Delay(1000);
//---------------------------------------------------------
//加载 unity
container = new UnityContainer();
Application.Current.Properties["container"] = container;
container.RegisterInstance(lp);
UnityConfExt.Load(container);
container.RegisterInstance<Window>(this);
//---------------------------------------------------------
//加载主界面布局
FlyLayout layout = new FlyLayout();
layout.Load();
//初始化
manager = new FlyLayoutManager();
container.RegisterInstance(manager);
manager.Init(
layout, container, lp);
this.DataContext = manager;
//以后的页面切换器
FlyLayoutManager.NavigationService = NavigationService;
//---------------------------------------------------------
//ui 加载前初始化
await manager.OnPreInit();
//加载模块构造主界面,如果是多设备界面, FlyLayoutManager.NavigationService 会被修改为 page内部的 NavigationService
var page = await manager.LoadModule();
NavigationService.Navigate(page);
page.Loaded += (s, e1) =>
frame.NavigationService.RemoveBackEntry();
//---------------------------------------------------------
//初始化
await manager.OnInit();
//启动Poll系统
//FObjBase.PollModule.Current.Start();
ErrMsgJsonDb jsonDb = new ErrMsgJsonDb();
if (jsonDb.Load()) {
var m = btnErrMsg.Margin;
m.Right = jsonDb.Right;
btnErrMsg.Margin = m;
}
}
private void btnErrMsgClick(object sender, RoutedEventArgs e)
{
manager.ErrMsgClick?.Invoke();
}
private void DrapMoveXBehavior_Move(object sender, EventArgs e)
{
ErrMsgJsonDb jsonDb = new ErrMsgJsonDb();
jsonDb.Right = (int)btnErrMsg.Margin.Right;
jsonDb.Save();
}
}
public class ErrMsgJsonDb
{
public int Right;
private string filePath = "errMsgPosition.json";
public bool Save()
{
try
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this);
File.WriteAllText(filePath, json);
return true;
}
catch
{
return false;
}
}
public bool Load()
{
if (!File.Exists(filePath))
return false;
try
{
string json = File.ReadAllText(filePath);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
return true;
}
catch {
return false;
}
}
}
public class WdMainVm:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public bool IsErrMsgVisable => !string.IsNullOrEmpty(ErrMsg);
/// <summary>
/// 错误信息
/// </summary>
public string ErrMsg { get; set; }
}
}