From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Componentes/CustomLegendChart.cs | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs (limited to 'Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs') diff --git a/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs b/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs new file mode 100644 index 0000000..ddbff3c --- /dev/null +++ b/Codemerx/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 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; + } +} \ No newline at end of file -- cgit v1.2.3