@ -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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,74 @@ |
|||||
<?xml version="1.0" encoding="utf-8" ?> |
<?xml version="1.0" encoding="utf-8" ?> |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="SunlightAggregationTerminal.InfoPage" |
x:Class="SunlightAggregationTerminal.InfoPage" |
||||
Title=""> |
xmlns:converters="clr-namespace:SunlightAggregationTerminal.Converters" |
||||
<VerticalStackLayout> |
Title="设备信息"> |
||||
|
<ContentPage.Resources> |
||||
</VerticalStackLayout> |
<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> |
</ContentPage> |
||||
@ -1,9 +1,26 @@ |
|||||
|
using SunlightAggregationTerminal.Models; |
||||
|
using System.Collections.ObjectModel; |
||||
|
|
||||
namespace SunlightAggregationTerminal; |
namespace SunlightAggregationTerminal; |
||||
|
|
||||
public partial class InfoPage : ContentPage |
public partial class InfoPage : ContentPage |
||||
{ |
{ |
||||
public InfoPage() |
public ObservableCollection<InfoItem> InfoItems { get; set; } = new(); |
||||
|
public InfoPage() |
||||
{ |
{ |
||||
InitializeComponent(); |
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) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
} |
} |
||||
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 132 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 231 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 38 KiB |