better precheck details handling
This commit is contained in:
parent
9693da7d37
commit
fc908386bc
39
SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs
Normal file
39
SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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">
|
||||
|
||||
<UserControl.Resources>
|
||||
<cvt:StateSpinnerStateToColorConverter x:Key="colorConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Panel>
|
||||
<StackPanel DataContext="{Binding RelativeSource={RelativeSource AncestorType=UserControl}}">
|
||||
<Label Content="Testing"/>
|
||||
<Label Content="{Binding PreChecks[SelectedIndex].Name}"/>
|
||||
<Label Content="{Binding PreChecks[SelectedIndex].State}"/>
|
||||
<Label Content="{Binding SelectedIndex}"/>
|
||||
</StackPanel>
|
||||
<!-- show when nothing is selected -->
|
||||
<!-- <Label Content="Select a Pre-Check to see more info" FontSize="20" -->
|
||||
<!-- HorizontalAlignment="Center" VerticalAlignment="Center" -->
|
||||
<!-- IsVisible="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static StringConverters.IsNullOrEmpty}}" -->
|
||||
<!-- /> -->
|
||||
<!-- -->
|
||||
<!-- ~1~ selected precheck details @1@ -->
|
||||
<!-- <Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10" -->
|
||||
<!-- IsVisible="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" -->
|
||||
<!-- > -->
|
||||
<!-- <Rectangle Grid.Row="1" Grid.Column="1" Width="3" Fill="{Binding BarColor, RelativeSource={RelativeSource AncestorType=UserControl}}" HorizontalAlignment="Left"/> -->
|
||||
<!-- -->
|
||||
<!-- <StackPanel Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left"> -->
|
||||
<!-- <Label Content="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}}" -->
|
||||
<!-- FontSize="20" -->
|
||||
<!-- /> -->
|
||||
<!-- <Rectangle Height="1" Fill="Gray" Margin="0 10"/> -->
|
||||
<!-- <TextBlock Text="{Binding Details, RelativeSource={RelativeSource AncestorType=UserControl}}" -->
|
||||
<!-- TextWrapping="Wrap" -->
|
||||
<!-- /> -->
|
||||
<!-- </StackPanel> -->
|
||||
<!-- -->
|
||||
<!-- <Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow" -->
|
||||
<!-- IsVisible="{Binding ShowAction, RelativeSource={RelativeSource AncestorType=UserControl}}" -->
|
||||
<!-- CornerRadius="15" -->
|
||||
<!-- Margin="0 10" -->
|
||||
<!-- Command="{Binding ActionCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" -->
|
||||
<!-- Content="{Binding ActionButtonText, RelativeSource={RelativeSource AncestorType=UserControl}}" -->
|
||||
<!-- HorizontalContentAlignment="Center" VerticalContentAlignment="Center" -->
|
||||
<!-- HorizontalAlignment="Stretch" -->
|
||||
<!-- /> -->
|
||||
<!-- -->
|
||||
<!-- </Grid> -->
|
||||
<!-- show when nothing is selected -->
|
||||
<Label Content="Select a Pre-Check to see more info" FontSize="20"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
IsVisible="{Binding HasSelection, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static BoolConverters.Not}}"
|
||||
/>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding PreChecks}" VerticalAlignment="Stretch">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="model:PreCheckBase">
|
||||
<!-- selected precheck details -->
|
||||
<Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10" VerticalAlignment="Stretch"
|
||||
IsVisible="{Binding IsSelected}"
|
||||
>
|
||||
<Rectangle Grid.Row="1" Grid.Column="1" Width="3" Fill="{Binding State, Converter={StaticResource colorConverter}}"
|
||||
HorizontalAlignment="Left"/>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left">
|
||||
<Label Content="{Binding Name}"
|
||||
FontSize="20"
|
||||
/>
|
||||
<Rectangle Height="1" Fill="Gray" Margin="0 10"/>
|
||||
<TextBlock Text="{Binding PreCheckDetails}"
|
||||
TextWrapping="Wrap"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow"
|
||||
IsVisible="{Binding ActionButtonIsVisible}"
|
||||
CornerRadius="15"
|
||||
Margin="0 10"
|
||||
Command="{Binding ActionButtonCommand}"
|
||||
Content="{Binding ActionButtonText}"
|
||||
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
/>
|
||||
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Panel>
|
||||
</UserControl>
|
||||
|
@ -21,12 +21,12 @@ public partial class PreCheckDetails : UserControl
|
||||
set => SetValue(PreChecksProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> SelectedIndexProperty =
|
||||
AvaloniaProperty.Register<PreCheckDetails, int>(nameof(SelectedIndex));
|
||||
public static readonly StyledProperty<bool> HasSelectionProperty =
|
||||
AvaloniaProperty.Register<PreCheckDetails, bool>(nameof(HasSelection));
|
||||
|
||||
public int SelectedIndex
|
||||
public bool HasSelection
|
||||
{
|
||||
get => GetValue(SelectedIndexProperty);
|
||||
set => SetValue(SelectedIndexProperty, value);
|
||||
get => GetValue(HasSelectionProperty);
|
||||
set => SetValue(HasSelectionProperty, value);
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class PreChecksViewModel : ViewModelBase
|
||||
{
|
||||
private int _selectedPreCheckIndex;
|
||||
private bool _hasPreCheckSelected;
|
||||
|
||||
public int SelectedPreCheckIndex
|
||||
public bool HasPreCheckSelected
|
||||
{
|
||||
get => _selectedPreCheckIndex;
|
||||
set => this.RaiseAndSetIfChanged(ref _selectedPreCheckIndex, value);
|
||||
get => _hasPreCheckSelected;
|
||||
set => this.RaiseAndSetIfChanged(ref _hasPreCheckSelected, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
|
||||
@ -209,7 +209,7 @@ public class PreChecksViewModel : ViewModelBase
|
||||
{
|
||||
precheck.IsSelected = true;
|
||||
|
||||
SelectedPreCheckIndex = PreChecks.IndexOf(precheck);
|
||||
HasPreCheckSelected = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
<!-- selected precheck details grid -->
|
||||
<cc:PreCheckDetails Grid.Row="2" Grid.Column="1"
|
||||
PreChecks="{Binding PreChecks}"
|
||||
SelectedIndex="{Binding SelectedPreCheckIndex}"
|
||||
HasSelection="{Binding HasPreCheckSelected}"
|
||||
/>
|
||||
|
||||
<!-- info card vertical separator -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user