using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using Tango.FSE.Common; using Tango.FSE.Insights.SciChart; using Tango.SharedUI.Components; namespace Tango.FSE.Insights.Dialogs { public class AnomaliesDialogViewVM : FSEDialogViewVM { private const int MAX_SELECTION = 8; private ICollectionView _view; public SelectedObjectCollection SelectedCharts { get; set; } private String _filter; public String Filter { get { return _filter; } set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } public bool MaximumSelectionReached { get { return SelectedCharts.SynchedSource.Count > MAX_SELECTION; } } public AnomaliesDialogViewVM(List availableCharts, List selectedCharts) { OKText = "ANALYZE"; SelectedCharts = new SelectedObjectCollection(availableCharts.OrderByDescending(x => selectedCharts.Contains(x)).ToObservableCollection(), selectedCharts.ToObservableCollection()); SelectedCharts.SelectionChanged += SelectedCharts_SelectionChanged; _view = CollectionViewSource.GetDefaultView(SelectedCharts); _view.Filter = FilterCharts; } private bool FilterCharts(object obj) { if (String.IsNullOrWhiteSpace(Filter)) return true; return (obj as SelectedObject).Data.Description.ToLower().Contains(Filter.ToLower()); } private void SelectedCharts_SelectionChanged(object sender, EventArgs e) { RaisePropertyChanged(nameof(MaximumSelectionReached)); InvalidateRelayCommands(); } protected override bool CanOK() { return base.CanOK() && SelectedCharts.SynchedSource.Count > 0 && !MaximumSelectionReached; } private void OnFilterChanged() { _view?.Refresh(); } } }