using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Media; using CommunityToolkit.Mvvm.Input; using OxyPlot; using OxyPlot.Series; using Shaker.Models; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace ShakerApp.ViewModels { internal class PlotConfigViewModel:DisplayViewModelBase { public override double Width => 750; public override double Height => 600; public override bool CanResize => false; public bool NoSeries { get => noSeries; set =>SetProperty(ref noSeries , value); } public AvaloniaList SeriesConfigs { get; } = new AvaloniaList(); private PlotConfigViewModel() { Content = typeof(Views.PlotConfigView); Title = "PlotConfig"; } static PlotConfigViewModel() { } public ICommand PlotConfigCommand => new RelayCommand(InitPlot); [AllowNull] private PlotModel _PlotModel; private bool noSeries = false; public async void InitPlot(object? sender, PlotModel? model) { if(model ==null || sender is not Control control) { NoSeries = true; SaveIsEnabled = false; return; } _PlotModel = model; SeriesConfigs.Clear(); var lists = _PlotModel.Series.OfType().ToList(); if (lists.Count == 0) { NoSeries = true; SaveIsEnabled = false; return; } NoSeries = false; SaveIsEnabled = true; lists.ForEach(x => SeriesConfigs.Add(new SeriesConfigViewModel(x))); base.InitData(); BaseDialogWindow window = new BaseDialogWindow(); window.DataContext = this; CloseWindowAction = () => window?.Close(); await window.ShowDialog((Window)Window.GetTopLevel(control)!); } protected override void Save() { base.Save(); var lists = _PlotModel.Series.OfType().ToList(); if (lists.Count == 0) return; _PlotModel.InvalidatePlot(false); try { /* * 关联的曲线可能由于后台通信指令重新加载 */ for(int i=0;i color; set =>SetProperty(ref color , value); } public LineStyle LineStyle { get => lineStyle; set =>SetProperty(ref lineStyle , value); } public MarkerType MarkerType { get => markerType; set =>SetProperty(ref markerType , value); } public double StrokeThickness { get => strokeThickness; set =>SetProperty(ref strokeThickness , value); } } }