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.Windows; using System.Windows.Controls; using System.Windows.Markup; using System.Windows.Media; using LiveCharts.Definitions.Series; using LiveCharts.Wpf; using LiveCharts.Wpf.Charts.Base; namespace Gestor.Application.Componentes; public class CustomLegendChart : UserControl, IChartLegend, INotifyPropertyChanged, IComponentConnector { public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(Orientation), typeof(CustomLegendChart), new PropertyMetadata((object)(Orientation)0)); internal ItemsControl itemsControl; private bool _contentLoaded; public Orientation Orientation { get { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return (Orientation)((DependencyObject)this).GetValue(OrientationProperty); } set { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((DependencyObject)this).SetValue(OrientationProperty, (object)value); } } public ObservableCollection LegendEntries { get; } = new ObservableCollection(); public List Series { get { return LegendEntries.Select((CustomSeriesViewModel x) => x.SeriesViewModel).ToList(); } set { Chart ownerChart = GetOwnerChart(); foreach (CustomSeriesViewModel item in LegendEntries.Where((CustomSeriesViewModel x) => !((IEnumerable)ownerChart.Series).Any((ISeriesView s) => s == x.View)).ToList()) { LegendEntries.Remove(item); } foreach (SeriesViewModel svm in value) { if (LegendEntries.All((CustomSeriesViewModel x) => x.Title != svm.Title)) { ISeriesView view = ((IEnumerable)ownerChart.Series).FirstOrDefault((Func)((ISeriesView x) => x.Title == svm.Title)); LegendEntries.Add(new CustomSeriesViewModel(svm, view)); } } OnPropertyChanged("Series"); } } public event PropertyChangedEventHandler PropertyChanged; public CustomLegendChart() { InitializeComponent(); ((FrameworkElement)itemsControl).DataContext = this; } private Chart GetOwnerChart() { return CustomLegendChart.FindParent((DependencyObject)(object)this); } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "") { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public static T FindParent(DependencyObject child) where T : DependencyObject { DependencyObject parent = VisualTreeHelper.GetParent(child); if (parent == null) { return default(T); } T val = (T)(object)((parent is T) ? parent : null); if (val != null) { return val; } return FindParent(parent); } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] public void InitializeComponent() { if (!_contentLoaded) { _contentLoaded = true; Uri uri = new Uri("/Gestor.Application;component/componentes/customlegendchart.xaml", UriKind.Relative); Application.LoadComponent((object)this, uri); } } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] [EditorBrowsable(EditorBrowsableState.Never)] void IComponentConnector.Connect(int connectionId, object target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if (connectionId == 1) { itemsControl = (ItemsControl)target; } else { _contentLoaded = true; } } }