Files
GSS2Rework/GSS2/ViewModels/AmineContentViewModel.cs
T
2026-08-13 09:56:08 +03:00

83 lines
3.2 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GSS2.UI.Core.Services;
using GSS2.ViewModels.Common;
using GSS2.ViewModels.AmineContent;
using ViewModelBase = GSS2.UI.Core.ViewModels.ViewModelBase;
using System.ComponentModel;
namespace GSS2.ViewModels;
public partial class AmineContentViewModel : ViewModelBase
{
private readonly NavigationService _navigationService;
[ObservableProperty] public partial AnalysisViewModel Analysis { get; set; }
[ObservableProperty] public partial SampleCalibrationViewModel SampleCalibration { get; set; }
[ObservableProperty] public partial SeparatorCalibrationViewModel SeparatorCalibration { get; set; }
// [ObservableProperty] public partial CameraViewModel Camera { get; set; }
[ObservableProperty] public partial BrandCalibrationViewModel BrandCalibration { get; set; }
[ObservableProperty] public partial ExportViewModel Export { get; set; }
// [ObservableProperty] public partial SystemViewModel System { get; set; }
[ObservableProperty] public partial int CurrentIndex { get; set; } = 0;
[ObservableProperty] public partial bool IsScrolling { get; set; } = false;
[ObservableProperty] public partial bool CanInteract { get; set; } = true;
public AmineContentViewModel(
NavigationService navigationService,
AnalysisViewModel analysis,
SampleCalibrationViewModel sampleCalibration,
SeparatorCalibrationViewModel separatorCalibration,
BrandCalibrationViewModel brandCalibration,
ExportViewModel export
)
{
_navigationService = navigationService;
Analysis = analysis;
SampleCalibration = sampleCalibration;
SeparatorCalibration = separatorCalibration;
BrandCalibration = brandCalibration;
Export = export;
PropertyChanged += (_, ea) =>
{
if (ea.PropertyName == nameof(IsScrolling))
UpdateCanInteract();
};
Analysis.PropertyChanged += SubViewModelPropertyChanged;
SampleCalibration.PropertyChanged += SubViewModelPropertyChanged;
SeparatorCalibration.PropertyChanged += SubViewModelPropertyChanged;
BrandCalibration.PropertyChanged += SubViewModelPropertyChanged;
}
private void SubViewModelPropertyChanged(object? sender, PropertyChangedEventArgs ea)
{
if (ea.PropertyName == nameof(Analysis.CanInteract) ||
ea.PropertyName == nameof(Analysis.ImagesIsCapturing))
UpdateCanInteract();
}
private void UpdateCanInteract()
{
CanInteract = !IsScrolling;
CanInteract &= Analysis.CanInteract;
CanInteract &= SampleCalibration.CanInteract;
CanInteract &= SeparatorCalibration.CanInteract;
CanInteract &= BrandCalibration.CanInteract;
CanInteract &= !Analysis.ImagesIsCapturing;
CanInteract &= !SampleCalibration.ImagesIsCapturing;
CanInteract &= !SeparatorCalibration.ImagesIsCapturing;
}
[RelayCommand]
void ChangeSection(string sectionNumberStr)
{
if (!int.TryParse(sectionNumberStr, out var sectionNumber))
return;
CurrentIndex = sectionNumber;
}
}