summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs
blob: ddbff3c4695b7e911ca4090e37f02a877f3aa13d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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<CustomSeriesViewModel> LegendEntries { get; } = new ObservableCollection<CustomSeriesViewModel>();

		public System.Windows.Controls.Orientation Orientation
		{
			get
			{
				return (System.Windows.Controls.Orientation)base.GetValue(CustomLegendChart.OrientationProperty);
			}
			set
			{
				base.SetValue(CustomLegendChart.OrientationProperty, value);
			}
		}

		public List<SeriesViewModel> Series
		{
			get
			{
				return (
					from x in this.LegendEntries
					select x.SeriesViewModel).ToList<SeriesViewModel>();
			}
			set
			{
				Chart ownerChart = this.GetOwnerChart();
				foreach (CustomSeriesViewModel list in (
					from x in this.LegendEntries
					where !ownerChart.get_Series().Any<ISeriesView>((ISeriesView s) => (object)s == (object)x.View)
					select x).ToList<CustomSeriesViewModel>())
				{
					this.LegendEntries.Remove(list);
				}
				foreach (SeriesViewModel seriesViewModel in value)
				{
					if (!this.LegendEntries.All<CustomSeriesViewModel>((CustomSeriesViewModel x) => x.Title != seriesViewModel.get_Title()))
					{
						continue;
					}
					ISeriesView seriesView = ownerChart.get_Series().FirstOrDefault<ISeriesView>((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<T>(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<T>(parent);
		}

		private Chart GetOwnerChart()
		{
			return CustomLegendChart.FindParent<Chart>(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;
	}
}