Browse Source

info页面添加下滑刷新

master
Administrator 3 months ago
parent
commit
8e4af75d05
  1. 4
      Class/TcpServer.cs
  2. 8
      InfoPage.xaml
  3. 28
      InfoPage.xaml.cs

4
Class/TcpServer.cs

@ -123,8 +123,8 @@ namespace SunlightAggregationTerminal.Class
if (data.TryGetValue("Info", out val) && val != null)//机台信息接受 if (data.TryGetValue("Info", out val) && val != null)//机台信息接受
{ {
DataModel.Info_data = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(val.ToString()!)!; DataModel.Info_data = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(val.ToString()!)!;
//发送消息 //发送消息
WeakReferenceMessenger.Default.Send(new object()); WeakReferenceMessenger.Default.Send(new object());
} }
if (data.TryGetValue("Query", out val) && val != null)//查询接受 if (data.TryGetValue("Query", out val) && val != null)//查询接受
{ {

8
InfoPage.xaml

@ -10,9 +10,8 @@
<converters:StringToBoolConverter x:Key="StringToBoolConverter" /> <converters:StringToBoolConverter x:Key="StringToBoolConverter" />
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<ScrollView> <RefreshView x:Name="myRefreshView_" >
<VerticalStackLayout Padding="20" Spacing="20"> <CollectionView x:Name="CardCollectionView"
<CollectionView x:Name="CardCollectionView"
RemainingItemsThreshold="5"> RemainingItemsThreshold="5">
<!-- 保持滚动条 --> <!-- 保持滚动条 -->
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
@ -83,6 +82,5 @@
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</VerticalStackLayout> </RefreshView>
</ScrollView>
</ContentPage> </ContentPage>

28
InfoPage.xaml.cs

@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using SunlightAggregationTerminal.Class; using SunlightAggregationTerminal.Class;
using SunlightAggregationTerminal.Models; using SunlightAggregationTerminal.Models;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -12,10 +13,11 @@ public partial class InfoPage : ContentPage
public static string? _Name, _State, _MachineName, _Machine, _Information, _Model, public static string? _Name, _State, _MachineName, _Machine, _Information, _Model,
_Type, _ModelA, _ModelB, _ModelC, _ModelD, _ModelE, _ModelF; _Type, _ModelA, _ModelB, _ModelC, _ModelD, _ModelE, _ModelF;
public InfoPage() public InfoPage()
{ {
InitializeComponent(); InitializeComponent();
CardCollectionView.ItemsSource = InfoItems; CardCollectionView.ItemsSource = InfoItems;
// 注册订阅一个不携带数据的消息(使用 object 作为泛型) // 注册订阅一个不携带数据的消息(使用 object 作为泛型)
WeakReferenceMessenger.Default.Register<object>(this, (r, m) => WeakReferenceMessenger.Default.Register<object>(this, (r, m) =>
@ -23,6 +25,10 @@ public partial class InfoPage : ContentPage
// 收到信号,直接触发函数 // 收到信号,直接触发函数
HandleUITrigger(); HandleUITrigger();
}); });
//注册当前页面的下滑刷新
myRefreshView_.Refreshing += (sender, e) => {
TcpServer.TcpTransmit("{\"Command\":\"Info\"}");
myRefreshView_.IsRefreshing = false; };
} }
private void HandleUITrigger() private void HandleUITrigger()
{ {
@ -61,24 +67,8 @@ public partial class InfoPage : ContentPage
}); });
} }
CardCollectionView.ItemsSource = InfoItems;
InfoItems.Add(new InfoItem myRefreshView_.IsRefreshing = false;
{
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()//关闭时注销消息 ~InfoPage()//关闭时注销消息

Loading…
Cancel
Save