From fc908386bcfbea450955e9c8d8c216bfa6e4ac1b Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 25 Mar 2024 18:19:16 -0400 Subject: [PATCH] better precheck details handling --- .../StateSpinnerStateToColorConverter.cs | 39 ++++++++ .../CustomControls/PreCheckDetails.axaml | 91 +++++++++++-------- .../CustomControls/PreCheckDetails.axaml.cs | 10 +- SPTInstaller/ViewModels/PreChecksViewModel.cs | 10 +- SPTInstaller/Views/PreChecksView.axaml | 2 +- 5 files changed, 102 insertions(+), 50 deletions(-) create mode 100644 SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs diff --git a/SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs b/SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs new file mode 100644 index 0000000..685e963 --- /dev/null +++ b/SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs @@ -0,0 +1,39 @@ +using System.Globalization; +using Avalonia.Data.Converters; +using Avalonia.Media; +using SPTInstaller.CustomControls; + +namespace SPTInstaller.Converters; + +public class StateSpinnerStateToColorConverter : IValueConverter +{ + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + if (value == null) + return null; + + if (value is not StatusSpinner.SpinnerState state) + return null; + + switch (state) + { + case StatusSpinner.SpinnerState.Pending: + return new SolidColorBrush(Colors.Gray); + case StatusSpinner.SpinnerState.Running: + return new SolidColorBrush(Colors.DodgerBlue); + case StatusSpinner.SpinnerState.OK: + return new SolidColorBrush(Colors.ForestGreen); + case StatusSpinner.SpinnerState.Warning: + return new SolidColorBrush(Colors.Goldenrod); + case StatusSpinner.SpinnerState.Error: + return new SolidColorBrush(Colors.Crimson); + default: + throw new ArgumentOutOfRangeException(); + } + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + return value; + } +} \ No newline at end of file diff --git a/SPTInstaller/CustomControls/PreCheckDetails.axaml b/SPTInstaller/CustomControls/PreCheckDetails.axaml index 2987bb3..0af7991 100644 --- a/SPTInstaller/CustomControls/PreCheckDetails.axaml +++ b/SPTInstaller/CustomControls/PreCheckDetails.axaml @@ -2,47 +2,60 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:model="using:SPTInstaller.Models" + xmlns:cvt="using:SPTInstaller.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SPTInstaller.CustomControls.PreCheckDetails"> + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +