|
|
|
@ -1,3 +1,4 @@ |
|
|
|
using CommunityToolkit.Mvvm.Messaging; |
|
|
|
using Microsoft.Maui.Controls; |
|
|
|
using SunlightAggregationTerminal.Class; |
|
|
|
using SunlightAggregationTerminal.Models; |
|
|
|
@ -6,21 +7,26 @@ using System.Collections.ObjectModel; |
|
|
|
namespace SunlightAggregationTerminal; |
|
|
|
|
|
|
|
public partial class InfoPage : ContentPage |
|
|
|
{ |
|
|
|
{ |
|
|
|
public static ObservableCollection<InfoItem> InfoItems { get; set; } = new(); |
|
|
|
public static string? _Name, _State, _MachineName, _Machine, _Information, _Model, |
|
|
|
_Type, _ModelA, _ModelB, _ModelC, _ModelD, _ModelE, _ModelF; |
|
|
|
|
|
|
|
public InfoPage() |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void OnInfoPage()//打开时加载信息
|
|
|
|
{ |
|
|
|
MainThread.BeginInvokeOnMainThread(() => |
|
|
|
InitializeComponent(); |
|
|
|
|
|
|
|
CardCollectionView.ItemsSource = InfoItems; |
|
|
|
// 注册订阅一个不携带数据的消息(使用 object 作为泛型)
|
|
|
|
WeakReferenceMessenger.Default.Register<object>(this, (r, m) => |
|
|
|
{ |
|
|
|
InfoItems.Clear(); |
|
|
|
// 收到信号,直接触发函数
|
|
|
|
HandleUITrigger(); |
|
|
|
}); |
|
|
|
} |
|
|
|
private void HandleUITrigger() |
|
|
|
{ |
|
|
|
InfoItems.Clear(); |
|
|
|
foreach (Dictionary<string, object> List in DataModel.Info_data) |
|
|
|
{ |
|
|
|
if (List.TryGetValue("Name", out var val) && val != null) _Name = val.ToString()!; |
|
|
|
@ -56,10 +62,30 @@ public partial class InfoPage : ContentPage |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
InfoItems.Add(new InfoItem |
|
|
|
{ |
|
|
|
Name = _Name, |
|
|
|
State = _State, |
|
|
|
MachineName = _MachineName, |
|
|
|
Machine = _Machine, |
|
|
|
Information = _Information, |
|
|
|
Type = _Type, |
|
|
|
Model = _Model, |
|
|
|
ModelA = _ModelA, |
|
|
|
ModelB = _ModelB, |
|
|
|
ModelC = _ModelC, |
|
|
|
ModelD = _ModelD, |
|
|
|
ModelE = _ModelE, |
|
|
|
ModelF = _ModelF |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
~InfoPage()//关闭时注销消息
|
|
|
|
{ |
|
|
|
WeakReferenceMessenger.Default.UnregisterAll(this); |
|
|
|
} |
|
|
|
|
|
|
|
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e) |
|
|
|
{ |
|
|
|
// 将 sender 强制转换为 BindingContext 定义在 BindableObject
|
|
|
|
|