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