trying something WIP

trying to see if I can just get the selected index and bind to it... doesn't seem to be working though ...
This commit is contained in:
IsWaffle 2024-03-25 16:12:15 -04:00
parent b94ed37f05
commit 0c82c4335f
4 changed files with 62 additions and 111 deletions

View File

@ -5,38 +5,44 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SPTInstaller.CustomControls.PreCheckDetails">
<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}}"
/>
<!-- selected precheck details -->
<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>
<!-- <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> -->
</Panel>
</UserControl>

View File

@ -1,6 +1,7 @@
using System.Windows.Input;
using System.Collections.ObjectModel;
using Avalonia;
using Avalonia.Controls;
using SPTInstaller.Models;
namespace SPTInstaller.CustomControls;
@ -11,57 +12,21 @@ public partial class PreCheckDetails : UserControl
InitializeComponent();
}
public static readonly StyledProperty<string> PreCheckNameProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(PreCheckName));
public static readonly StyledProperty<ObservableCollection<PreCheckBase>> PreChecksProperty =
AvaloniaProperty.Register<PreCheckDetails, ObservableCollection<PreCheckBase>>(nameof(PreChecks));
public string PreCheckName
public ObservableCollection<PreCheckBase> PreChecks
{
get => GetValue(PreCheckNameProperty);
set => SetValue(PreCheckNameProperty, value);
get => GetValue(PreChecksProperty);
set => SetValue(PreChecksProperty, value);
}
public static readonly StyledProperty<string> DetailsProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(Details));
public static readonly StyledProperty<int> SelectedIndexProperty =
AvaloniaProperty.Register<PreCheckDetails, int>(nameof(SelectedIndex));
public string Details
public int SelectedIndex
{
get => GetValue(DetailsProperty);
set => SetValue(DetailsProperty, value);
}
public static readonly StyledProperty<string> ActionButtonTextProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(ActionButtonText));
public string ActionButtonText
{
get => GetValue(ActionButtonTextProperty);
set => SetValue(ActionButtonTextProperty, value);
}
public static readonly StyledProperty<ICommand> ActionCommandProperty =
AvaloniaProperty.Register<PreCheckDetails, ICommand>(nameof(ActionCommand));
public ICommand ActionCommand
{
get => GetValue(ActionCommandProperty);
set => SetValue(ActionCommandProperty, value);
}
public static readonly StyledProperty<bool> ShowActionProperty =
AvaloniaProperty.Register<PreCheckDetails, bool>(nameof(ShowAction));
public bool ShowAction
{
get => GetValue(ShowActionProperty);
set => SetValue(ShowActionProperty, value);
}
public static readonly StyledProperty<string> BarColorProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(BarColor));
public string BarColor
{
get => GetValue(BarColorProperty);
set => SetValue(BarColorProperty, value);
get => GetValue(SelectedIndexProperty);
set => SetValue(SelectedIndexProperty, value);
}
}

View File

@ -19,7 +19,13 @@ namespace SPTInstaller.ViewModels;
public class PreChecksViewModel : ViewModelBase
{
public PreCheckDetailInfo SelectedPreCheck { get; set; } = new();
private int _selectedPreCheckIndex;
public int SelectedPreCheckIndex
{
get => _selectedPreCheckIndex;
set => this.RaiseAndSetIfChanged(ref _selectedPreCheckIndex, value);
}
public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
@ -202,30 +208,8 @@ public class PreChecksViewModel : ViewModelBase
if (check.Id == precheck.Id)
{
precheck.IsSelected = true;
SelectedPreCheck.Name = precheck.Name;
SelectedPreCheck.Details = precheck.PreCheckDetails;
SelectedPreCheck.ActionButtonText = precheck.ActionButtonText;
SelectedPreCheck.ActionButtonCommand = precheck.ActionButtonCommand;
SelectedPreCheck.ShowActionButton = precheck.ActionButtonIsVisible;
switch (precheck.State)
{
case StatusSpinner.SpinnerState.Pending:
SelectedPreCheck.BarColor = "gray";
break;
case StatusSpinner.SpinnerState.Running:
SelectedPreCheck.BarColor = "dodgerblue";
break;
case StatusSpinner.SpinnerState.OK:
SelectedPreCheck.BarColor = "forestgreen";
break;
case StatusSpinner.SpinnerState.Warning:
SelectedPreCheck.BarColor = "gold";
break;
case StatusSpinner.SpinnerState.Error:
SelectedPreCheck.BarColor = "red";
break;
}
SelectedPreCheckIndex = PreChecks.IndexOf(precheck);
continue;
}

View File

@ -20,14 +20,10 @@
/>
<!-- selected precheck details grid -->
<cc:PreCheckDetails Grid.Row="2" Grid.Column="1"
PreCheckName="{Binding SelectedPreCheck.Name}"
Details="{Binding SelectedPreCheck.Details}"
ActionButtonText="{Binding SelectedPreCheck.ActionButtonText}"
ActionCommand="{Binding SelectedPreCheck.ActionButtonCommand}"
ShowAction="{Binding SelectedPreCheck.ShowActionButton}"
BarColor="{Binding SelectedPreCheck.BarColor}"
/>
<cc:PreCheckDetails Grid.Row="2" Grid.Column="1"
PreChecks="{Binding PreChecks}"
SelectedIndex="{Binding SelectedPreCheckIndex}"
/>
<!-- info card vertical separator -->
<Rectangle Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" VerticalAlignment="Stretch"