using Avalonia.Collections; using Avalonia.Controls; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShakerApp.ViewModels { internal class ShakerChannelViewModel:DisplayViewModelBase { public override bool CanResize => false; public override double Height => 420; public override double Width => 560; public AvaloniaList Channels { get; } = new AvaloniaList(); [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.DisplacementChannel))] public int DisplacementChannel { get => Model.DisplacementChannel; set => SetProperty(ref Model.DisplacementChannel, value); } [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel0))] public int AccelerationChannel0 { get => Model.AccelerationChannel0; set => SetProperty(ref Model.AccelerationChannel0, value); } [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel1))] public int AccelerationChannel1 { get => Model.AccelerationChannel1; set => SetProperty(ref Model.AccelerationChannel1, value); } [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.OutSignalChannel))] public int OutSignalChannel { get => Model.OutSignalChannel; set => SetProperty(ref Model.OutSignalChannel, value); } protected override bool SkipProperty(string? propertyName) { cansave = true; return base.SkipProperty(propertyName); } private ShakerChannelViewModel() { Content = typeof(Views.ShakerChannelView); Channels.Clear(); Channels.AddRange(Enumerable.Range(0, Shaker.Models.ShakerChannelModel.MaxChannel)); GetEvent().Subscrip((sender,args) => { UpDateModel(args.Data.ShakerChannel); CommunicationViewModel.Instance.LocalCommunication?.GetEvent()?.Subscrip((sender, args) => { UpDateModel(args.Data); CommunicationViewModel.Instance.ServiceCommunication?.GetEvent()?.Publish(this, Model); }); }); } static ShakerChannelViewModel() { } protected override void Save() { List channels = new List() { DisplacementChannel, AccelerationChannel0, AccelerationChannel1, OutSignalChannel }; int oldch = channels.Count; if(channels.Distinct().Count()!=oldch) { SaveClose = false; this.ShowError(App.Current?.FindResource("ChannelRepeatError")+""); return; } base.Save(); } public static ShakerChannelViewModel Instance { get; } = new ShakerChannelViewModel(); } }