UI界面
This commit is contained in:
@@ -1,25 +1,112 @@
|
||||
using Model.Entity;
|
||||
using Prism.Commands;
|
||||
using Prism.Ioc;
|
||||
using Service.Interface;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace MainModule.ViewModels
|
||||
{
|
||||
public class MainViewModel : NavigateViewModelBase
|
||||
{
|
||||
|
||||
#region 私有字段
|
||||
public ObservableCollection<ChamberMonitorItem> Chambers { get; } = new();
|
||||
private IContainerProvider _containerProvider;
|
||||
|
||||
#endregion
|
||||
public MainViewModel(IContainerProvider containerProvider ) : base(containerProvider)
|
||||
public MainViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
_containerProvider=containerProvider;
|
||||
_containerProvider = containerProvider;
|
||||
|
||||
// 触发配置与绑定初始化
|
||||
ConfigureAndBindChambers();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 核心配置与数据绑定逻辑
|
||||
/// </summary>
|
||||
private void ConfigureAndBindChambers()
|
||||
{
|
||||
// 实例 1:Modbus TCP 环境箱配置
|
||||
Chambers.Add(new ChamberMonitorItem
|
||||
{
|
||||
Id = 1,
|
||||
Name = "环境箱 01",
|
||||
ProtocolType = "Modbus TCP",
|
||||
IsConnected = false,
|
||||
Temperature = 0.0,
|
||||
Humidity = 0.0
|
||||
});
|
||||
|
||||
// 实例 2:Modbus TCP B+ 环境箱配置
|
||||
Chambers.Add(new ChamberMonitorItem
|
||||
{
|
||||
Id = 2,
|
||||
Name = "环境箱 02",
|
||||
ProtocolType = "Modbus TCP B+",
|
||||
IsConnected = false,
|
||||
Temperature = 0.0,
|
||||
Humidity = 0.0
|
||||
});
|
||||
|
||||
// 实例 3:西门子 S7 环境箱配置
|
||||
Chambers.Add(new ChamberMonitorItem
|
||||
{
|
||||
Id = 3,
|
||||
Name = "环境箱 03",
|
||||
ProtocolType = "S7",
|
||||
IsConnected = false,
|
||||
Temperature = 0.0,
|
||||
Humidity = 0.0
|
||||
});
|
||||
|
||||
// 实例 4:HTTP 环境箱配置
|
||||
Chambers.Add(new ChamberMonitorItem
|
||||
{
|
||||
Id = 4,
|
||||
Name = "环境箱 04",
|
||||
ProtocolType = "HTTP",
|
||||
IsConnected = false,
|
||||
Temperature = 0.0,
|
||||
Humidity = 0.0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 环境箱 UI 状态及温湿度数据绑定模型
|
||||
/// </summary>
|
||||
public class ChamberMonitorItem :BindableBase
|
||||
{
|
||||
private double _temperature;
|
||||
private double _humidity;
|
||||
private bool _isConnected;
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string ProtocolType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 温度(支持通知刷新)
|
||||
/// </summary>
|
||||
public double Temperature
|
||||
{
|
||||
get => _temperature;
|
||||
set => SetProperty(ref _temperature, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 湿度(支持通知刷新)
|
||||
/// </summary>
|
||||
public double Humidity
|
||||
{
|
||||
get => _humidity;
|
||||
set => SetProperty(ref _humidity, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接状态:True-已连接(绿灯),False-断开(红灯)
|
||||
/// </summary>
|
||||
public bool IsConnected
|
||||
{
|
||||
get => _isConnected;
|
||||
set => SetProperty(ref _isConnected, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,91 @@
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
</UserControl.Resources>
|
||||
|
||||
|
||||
</UserControl>
|
||||
|
||||
<Grid Background="#F4F6F9">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Text="环境箱监控状态面板" FontSize="20" FontWeight="Bold" Foreground="#2C3E50" Margin="12,4,0,16"/>
|
||||
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding Chambers}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Rows="2" Margin="-6"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="White" BorderBrush="#E2E8F0" BorderThickness="1" CornerRadius="8" Margin="6" Padding="20">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect BlurRadius="8" Color="#A0AEC0" Opacity="0.15" ShadowDepth="1"/>
|
||||
</Border.Effect>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<DockPanel Grid.Row="0" LastChildFill="False">
|
||||
<StackPanel DockPanel.Dock="Left">
|
||||
<TextBlock Text="{Binding Name}" FontSize="16" FontWeight="Bold" Foreground="#1A202C"/>
|
||||
<TextBlock Text="{Binding ProtocolType, StringFormat=驱动协议: {0}}" FontSize="12" Foreground="#718096" Margin="0,2,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0" VerticalAlignment="Center">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#E53E3E"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#38A169"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="13" FontWeight="Medium">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="OFFLINE"/>
|
||||
<Setter Property="Foreground" Value="#E53E3E"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="ONLINE"/>
|
||||
<Setter Property="Foreground" Value="#38A169"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
<UniformGrid Grid.Row="1" Columns="2" Margin="0,20,0,0">
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="温度采集" FontSize="13" Foreground="#718096" HorizontalAlignment="Center"/>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,6,0,0">
|
||||
<TextBlock Text="{Binding Temperature, StringFormat={}{0:F1}}" FontSize="40" FontWeight="Light" Foreground="#3182CE"/>
|
||||
<TextBlock Text=" ℃" FontSize="16" Foreground="#3182CE" VerticalAlignment="Bottom" Margin="2,0,0,8"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="湿度采集" FontSize="13" Foreground="#718096" HorizontalAlignment="Center"/>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,6,0,0">
|
||||
<TextBlock Text="{Binding Humidity, StringFormat={}{0:F1}}" FontSize="40" FontWeight="Light" Foreground="#319795"/>
|
||||
<TextBlock Text=" %RH" FontSize="16" Foreground="#319795" VerticalAlignment="Bottom" Margin="2,0,0,8"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UniformGrid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Reference in New Issue
Block a user