using LiveCharts.Definitions.Series; using LiveCharts.Wpf; using LiveCharts.Wpf.Charts.Base; using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Markup; using System.Windows.Media; namespace Gestor.Application.Componentes { public class CustomLegendChart : UserControl, IChartLegend, INotifyPropertyChanged, IComponentConnector { public readonly static DependencyProperty OrientationProperty; internal ItemsControl itemsControl; private bool _contentLoaded; public ObservableCollection LegendEntries { get; } = new ObservableCollection(); public System.Windows.Controls.Orientation Orientation { get { return (System.Windows.Controls.Orientation)base.GetValue(CustomLegendChart.OrientationProperty); } set { base.SetValue(CustomLegendChart.OrientationProperty, value); } } public List Series { get { return ( from x in this.LegendEntries select x.SeriesViewModel).ToList(); } set { Chart ownerChart = this.GetOwnerChart(); foreach (CustomSeriesViewModel list in ( from x in this.LegendEntries where !ownerChart.get_Series().Any((ISeriesView s) => (object)s == (object)x.View) select x).ToList()) { this.LegendEntries.Remove(list); } foreach (SeriesViewModel seriesViewModel in value) { if (!this.LegendEntries.All((CustomSeriesViewModel x) => x.Title != seriesViewModel.get_Title())) { continue; } ISeriesView seriesView = ownerChart.get_Series().FirstOrDefault((ISeriesView x) => x.get_Title() == seriesViewModel.get_Title()); this.LegendEntries.Add(new CustomSeriesViewModel(seriesViewModel, seriesView)); } this.OnPropertyChanged("Series"); } } static CustomLegendChart() { CustomLegendChart.OrientationProperty = DependencyProperty.Register("Orientation", typeof(System.Windows.Controls.Orientation), typeof(CustomLegendChart), new PropertyMetadata((object)System.Windows.Controls.Orientation.Horizontal)); } public CustomLegendChart() { this.InitializeComponent(); this.itemsControl.DataContext = this; } public static T FindParent(DependencyObject child) where T : DependencyObject { DependencyObject parent = VisualTreeHelper.GetParent(child); if (parent == null) { return default(T); } T t = (T)(parent as T); if (t != null) { return t; } return CustomLegendChart.FindParent(parent); } private Chart GetOwnerChart() { return CustomLegendChart.FindParent(this); } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] public void InitializeComponent() { if (this._contentLoaded) { return; } this._contentLoaded = true; System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/componentes/customlegendchart.xaml", UriKind.Relative)); } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "") { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { if (connectionId != 1) { this._contentLoaded = true; return; } this.itemsControl = (ItemsControl)target; } public event PropertyChangedEventHandler PropertyChanged; } }