MetaforceInstaller/MetaforceInstaller.UI/ViewModels/MainWindowViewModel.cs

65 lines
No EOL
1.8 KiB
C#

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia.Media;
using MetaforceInstaller.Core.Models;
namespace MetaforceInstaller.UI.ViewModels;
public class MainWindowViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public ObservableCollection<InstallationData> Installations { get; set; } = new();
private bool _isDeviceConnected;
public bool IsDeviceConnected
{
get => _isDeviceConnected;
set
{
if (_isDeviceConnected != value)
{
_isDeviceConnected = value;
OnPropertyChanged();
OnPropertyChanged(nameof(StatusColor));
OnPropertyChanged(nameof(StatusText));
}
}
}
private string _deviceSerial = string.Empty;
public string DeviceSerial
{
get => _deviceSerial;
set
{
if (_deviceSerial != value)
{
_deviceSerial = value;
OnPropertyChanged();
OnPropertyChanged(nameof(StatusText));
}
}
}
public IBrush StatusColor => IsDeviceConnected ? Brushes.Green : Brushes.Red;
public string StatusText => IsDeviceConnected ? $"Connected to {_deviceSerial}" : "Not connected";
public void LoadInstallations(IEnumerable<InstallationData> data)
{
Installations.Clear();
foreach (var installation in data)
{
Installations.Add(installation);
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}