53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using GazpromApp.Messages;
|
|
using GazpromApp.Models;
|
|
|
|
namespace GazpromApp.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
public ObservableCollection<PointViewModel> Points { get; } = [];
|
|
|
|
[RelayCommand]
|
|
private async Task AddPoint()
|
|
{
|
|
var point = await WeakReferenceMessenger.Default.Send(new NewPointMessage());
|
|
|
|
if (point != null)
|
|
Points.Add(point);
|
|
|
|
IsLineVisible = Points.Count > 0;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task EditPoint(PointViewModel point)
|
|
{
|
|
var p = await WeakReferenceMessenger.Default.Send(new EditPointMessage(point)) ?? point;
|
|
Points[Points.IndexOf(point)] = p;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void RemovePoint(PointViewModel point)
|
|
{
|
|
Points.Remove(point);
|
|
|
|
IsLineVisible = Points.Count > 0;
|
|
}
|
|
|
|
// Visual properties
|
|
|
|
[ObservableProperty]
|
|
private bool _isLineVisible;
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
if (Design.IsDesignMode)
|
|
Points = [new PointViewModel(new Point()) { Name = "Name test", Description = "Description test" }];
|
|
else Points = [];
|
|
}
|
|
} |