From ea35183f1c869486e443f9e9b56bd8f7f28e20aa Mon Sep 17 00:00:00 2001 From: noberumotto Date: Fri, 17 Jun 2022 08:34:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9F=B1=E7=8A=B6=E5=9B=BE?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI/Controls/Charts/Charts.cs | 70 +++++++++++++++++++++++- UI/Themes/Charts/Charts.xaml | 101 ++++++++++++++++++++++++++++++++++- 2 files changed, 167 insertions(+), 4 deletions(-) diff --git a/UI/Controls/Charts/Charts.cs b/UI/Controls/Charts/Charts.cs index 941dec2..d4806ed 100644 --- a/UI/Controls/Charts/Charts.cs +++ b/UI/Controls/Charts/Charts.cs @@ -295,6 +295,47 @@ namespace UI.Controls.Charts #endregion + public bool IsShowValuesPopup + { + get { return (bool)GetValue(IsShowValuesPopupProperty); } + set { SetValue(IsShowValuesPopupProperty, value); } + } + public static readonly DependencyProperty IsShowValuesPopupProperty = + DependencyProperty.Register("IsShowValuesPopup", + typeof(bool), + typeof(Charts), + new PropertyMetadata(false)); + public FrameworkElement ValuesPopupPlacementTarget + { + get { return (FrameworkElement)GetValue(ValuesPopupPlacementTargetProperty); } + set { SetValue(ValuesPopupPlacementTargetProperty, value); } + } + public static readonly DependencyProperty ValuesPopupPlacementTargetProperty = + DependencyProperty.Register("ValuesPopupPlacementTarget", + typeof(FrameworkElement), + typeof(Charts)); + + public List ColumnValuesInfoList + { + get { return (List)GetValue(ColumnValuesInfoListProperty); } + set { SetValue(ColumnValuesInfoListProperty, value); } + } + public static readonly DependencyProperty ColumnValuesInfoListProperty = + DependencyProperty.Register("ColumnValuesInfoList", + typeof(List), + typeof(Charts) + ); + + public double ValuesPopupHorizontalOffset + { + get { return (double)GetValue(ValuesPopupHorizontalOffsetProperty); } + set { SetValue(ValuesPopupHorizontalOffsetProperty, value); } + } + public static readonly DependencyProperty ValuesPopupHorizontalOffsetProperty = + DependencyProperty.Register("ValuesPopupHorizontalOffset", + typeof(double), + typeof(Charts)); + private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var charts = (d as Charts); @@ -853,7 +894,13 @@ namespace UI.Controls.Charts Width = new GridLength(1, GridUnitType.Star) }); + var valueContainer = new Grid(); + + Grid.SetColumn(valueContainer, i); + ColumnContainer.Children.Add(valueContainer); + var valuesPopupList = new List(); + for (int di = 0; di < columnCount; di++) { var item = list[di]; @@ -866,11 +913,30 @@ namespace UI.Controls.Charts column.Color = item.Color; column.ColumnName = item.ColumnNames != null && item.ColumnNames.Length > 0 ? item.ColumnNames[i] : (i + NameIndexStart).ToString(); Panel.SetZIndex(column, column.Value > 0 ? -(int)column.Value : 0); - Grid.SetColumn(column, i); - ColumnContainer.Children.Add(column); + + valueContainer.Children.Add(column); + + valuesPopupList.Add(new ChartColumnInfoModel() + { + Color = item.Color, + Name = item.Name, + Icon = item.Icon, + Text = Covervalue(column.Value) + Unit + }); } + valueContainer.MouseEnter += (e, c) => + { + ColumnValuesInfoList = valuesPopupList; + ValuesPopupPlacementTarget = valueContainer; + IsShowValuesPopup = true; + ValuesPopupHorizontalOffset = -17.5 + (valueContainer.ActualWidth / 2); + }; + valueContainer.MouseLeave += (e, c) => + { + IsShowValuesPopup = false; + }; } var infoList = new List(); diff --git a/UI/Themes/Charts/Charts.xaml b/UI/Themes/Charts/Charts.xaml index 15dcbd1..c36be56 100644 --- a/UI/Themes/Charts/Charts.xaml +++ b/UI/Themes/Charts/Charts.xaml @@ -38,12 +38,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + StrokeDashArray="2 5" StrokeThickness=".8" VerticalAlignment="Center" Margin="10,0,10,30"/>