Browse Source

添加设备图片资源

添加信息页面标签卡
master
Administrator 3 months ago
parent
commit
9432d935c3
  1. 38
      Converters/StringToImageConverter.cs
  2. 75
      InfoPage.xaml
  3. 21
      InfoPage.xaml.cs
  4. 16
      Models/DataSource.cs
  5. BIN
      Resources/Images/sc242w.png
  6. BIN
      Resources/Images/sc2522t.png
  7. BIN
      Resources/Images/sc252rb.png
  8. BIN
      Resources/Images/sc252rmrd.png
  9. BIN
      Resources/Images/sc302.png
  10. BIN
      Resources/Images/sc303.png
  11. BIN
      Resources/Images/sc303pdw.png
  12. BIN
      Resources/Images/sunlight_logo.jpg
  13. BIN
      Resources/Images/sunlight_logotext.jpg
  14. BIN
      Resources/Images/sunlight_sc.png
  15. BIN
      Resources/Images/sunlightlogo.jpg

38
Converters/StringToImageConverter.cs

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using Microsoft.Maui.Controls;
namespace SunlightAggregationTerminal.Converters
{
public class StringToImageConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value !=null)
{
// 根据字符串内容返回对应的图片路径
// 确保你的 Resources/Raw 或 Resources/Images 目录下有这些图片
if (value.ToString() == "252") return ImageSource.FromFile("sc252rb.png");
else if (value.ToString() == "252-2T") return ImageSource.FromFile("sc2522t.png");
else if (value.ToString() == "252RB") return ImageSource.FromFile("sc252rb.png");
else if (value.ToString() == "252RDRM") return ImageSource.FromFile("sc252rdrm.png");
else if (value.ToString() == "242W") return ImageSource.FromFile("sc242w.png");
else if (value.ToString() == "302") return ImageSource.FromFile("sc302.png");
else if (value.ToString() == "303") return ImageSource.FromFile("sc303.png");
else if (value.ToString() == "303PDW") return ImageSource.FromFile("sc303pdw.png");
else return ImageSource.FromFile("sunlightlogo.png");
}
// 如果值为空或类型不对,返回默认值或 null
return ImageSource.FromFile("sunlightlogo.png");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// 通常图片转回字符串在 UI 上很少用到,可以抛出异常或留空
throw new NotImplementedException();
}
}
}

75
InfoPage.xaml

@ -1,9 +1,74 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SunlightAggregationTerminal.InfoPage"
Title="">
<VerticalStackLayout>
</VerticalStackLayout>
x:Class="SunlightAggregationTerminal.InfoPage"
xmlns:converters="clr-namespace:SunlightAggregationTerminal.Converters"
Title="设备信息">
<ContentPage.Resources>
<ResourceDictionary>
<converters:StringToImageConverter x:Key="StringToImageConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<ScrollView>
<VerticalStackLayout Padding="20" Spacing="20">
<CollectionView x:Name="CardCollectionView"
ItemsSource="{Binding InfoItems}"
RemainingItemsThreshold="5">
<!-- 保持滚动条 -->
<CollectionView.ItemTemplate>
<DataTemplate>
<!-- 这里定义单个卡片的 UI 结构 -->
<Border BackgroundColor="White" Stroke="#CCCCCC"
StrokeThickness="2" Margin="10,0,10,10"
StrokeShape="RoundRectangle 10">
<Grid>
<!-- 定义一行 -->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" BackgroundColor="#CCCCCC">
<Label Text="{Binding Name}" FontAttributes="Bold"
FontSize="24" TextColor="Black"
Padding="5"/>
</Grid>
<Grid Grid.Row="1">
<VerticalStackLayout>
<Grid>
<HorizontalStackLayout>
<!-- 图片 -->
<Image WidthRequest="100" HeightRequest="100"
Source="{Binding Path=Model, Converter={StaticResource StringToImageConverter}}"/>
<!-- 设备状态 -->
<VerticalStackLayout>
<HorizontalStackLayout>
<Label Text="状态: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
<Label Text="{Binding State}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="机台: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
<Label Text="{Binding Machine}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</HorizontalStackLayout>
</Grid>
<BoxView HeightRequest="3" Color="#CCCCCC" />
<HorizontalStackLayout>
<!-- 设备信息 -->
<Label Text="{Binding Information}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</Grid>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

21
InfoPage.xaml.cs

@ -1,9 +1,26 @@
using SunlightAggregationTerminal.Models;
using System.Collections.ObjectModel;
namespace SunlightAggregationTerminal;
public partial class InfoPage : ContentPage
{
public InfoPage()
public ObservableCollection<InfoItem> InfoItems { get; set; } = new();
public InfoPage()
{
InitializeComponent();
}
InfoItems.Add(new InfoItem { Name="202",Model= "302", State="tz",Machine="123456",Information="etggsgt\n234423\ngsgsg\nstset" });
InfoItems.Add(new InfoItem { Name = "pdw", Model = "252-2T", State = "tz", Machine = "123456", Information = "etggsgt\n234423\ngsgsg\nstset" });
InfoItems.Add(new InfoItem { Name = "pdw", Model = "242W", State = "tz", Machine = "123456", Information = "etggsgt\n234423\ngsgsg\nstset" });
CardCollectionView.ItemsSource = InfoItems;
}
private void CardCollectionView_RemainingItemsThresholdReached(object sender, EventArgs e)
{
}
}

16
Models/DataSource.cs

@ -23,6 +23,22 @@ namespace SunlightAggregationTerminal.Models
public DateTime Time { get; set; }
public MsgType Type { get; set; }
}
public class InfoItem
{
public string? Name { get; set; }
public string? State { get; set; }
public string? Machine { get; set; }
public string? Information { get; set; }
public string? Model { get; set; }
public string? Type { get; set; }
public string? A { get; set; }
public string? B { get; set; }
public string? C { get; set; }
public string? D { get; set; }
public string? E { get; set; }
public string? F { get; set; }
}
public class DyelotItem
{
public string? Dyelot { get; set; }

BIN
Resources/Images/sc242w.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
Resources/Images/sc2522t.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

BIN
Resources/Images/sc252rb.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
Resources/Images/sc252rmrd.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

BIN
Resources/Images/sc302.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
Resources/Images/sc303.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
Resources/Images/sc303pdw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

BIN
Resources/Images/sunlight_logo.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
Resources/Images/sunlight_logotext.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

BIN
Resources/Images/sunlight_sc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
Resources/Images/sunlightlogo.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Loading…
Cancel
Save