Forr谩sk贸d B枚ng茅sz茅se

褰诲簳淇鎶ヨ璇︽儏绌哄 - 鏀圭敤ViewModel鎵佸钩灞炴ф浛浠e祵濂楃粦瀹

纾 鏇 1 hete
sz眉l艖
commit
449282aec4

+ 4 - 4
src/YZWater.Avalonia/Views/ViewDView.axaml

@@ -72,19 +72,19 @@
                         IsVisible="{Binding SelectedRecord, Converter={x:Static ObjectConverters.IsNotNull}}">
                     <Grid ColumnDefinitions="80,*" RowDefinitions="Auto,Auto,Auto,Auto">
                         <TextBlock Grid.Row="0" Grid.Column="0" Text="TIME" FontFamily="{DynamicResource MonoFont}" FontSize="10" Foreground="{DynamicResource TextTertiaryBrush}"/>
-                        <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding SelectedRecord.AlarmTime, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}', FallbackValue='--'}"
+                        <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding DetailTime}"
                                    FontFamily="{DynamicResource MonoFont}" FontSize="11" Foreground="{DynamicResource TextPrimaryBrush}"/>
 
                         <TextBlock Grid.Row="1" Grid.Column="0" Text="TYPE" FontFamily="{DynamicResource MonoFont}" FontSize="10" Foreground="{DynamicResource TextTertiaryBrush}"/>
-                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding SelectedRecord.AlarmType, FallbackValue='--'}"
+                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding DetailType}"
                                    FontFamily="{DynamicResource MonoFont}" FontSize="11" Foreground="{DynamicResource WarningBrush}"/>
 
                         <TextBlock Grid.Row="2" Grid.Column="0" Text="MESSAGE" FontFamily="{DynamicResource MonoFont}" FontSize="10" Foreground="{DynamicResource TextTertiaryBrush}"/>
-                        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding SelectedRecord.AlarmMessage, FallbackValue='--'}"
+                        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding DetailMessage}"
                                    FontFamily="{DynamicResource MonoFont}" FontSize="11" Foreground="{DynamicResource DangerBrush}"/>
 
                         <TextBlock Grid.Row="3" Grid.Column="0" Text="LEVEL" FontFamily="{DynamicResource MonoFont}" FontSize="10" Foreground="{DynamicResource TextTertiaryBrush}"/>
-                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding SelectedRecord.AlarmLevel, StringFormat='{}Level {0}', FallbackValue='--'}"
+                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding DetailLevel}"
                                    FontFamily="{DynamicResource MonoFont}" FontSize="11" Foreground="{DynamicResource TextPrimaryBrush}"/>
                     </Grid>
                 </Border>

+ 14 - 0
src/YZWater.Core/ViewModels/ViewDViewModel.cs

@@ -29,6 +29,20 @@ public partial class ViewDViewModel : ObservableObject
     [ObservableProperty]
     private string _filterType = "鍏ㄩ儴";
 
+    // 璇︽儏瀛楁锛堥伩鍏 SelectedRecord 涓 null 鏃跺祵濂楃粦瀹氭姤閿欙級
+    [ObservableProperty] private string _detailTime = "--";
+    [ObservableProperty] private string _detailType = "--";
+    [ObservableProperty] private string _detailMessage = "--";
+    [ObservableProperty] private string _detailLevel = "--";
+
+    partial void OnSelectedRecordChanged(AlarmRecord? value)
+    {
+        DetailTime = value?.AlarmTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "--";
+        DetailType = value?.AlarmType ?? "--";
+        DetailMessage = value?.AlarmMessage ?? "--";
+        DetailLevel = value != null ? $"Level {value.AlarmLevel}" : "--";
+    }
+
     public ViewDViewModel()
     {
         _ = LoadAlarmRecordsAsync();