diff options
Diffstat (limited to 'Gestor.Application/Componentes/CustomLegendChart.cs')
| -rw-r--r-- | Gestor.Application/Componentes/CustomLegendChart.cs | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/Gestor.Application/Componentes/CustomLegendChart.cs b/Gestor.Application/Componentes/CustomLegendChart.cs new file mode 100644 index 0000000..ddbff3c --- /dev/null +++ b/Gestor.Application/Componentes/CustomLegendChart.cs @@ -0,0 +1,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;
+ }
+}
\ No newline at end of file |