Skip to content

Commit a1135f0

Browse files
Merge pull request #176 from aruljenithberkmans/tooltipAppThemeBinding-issue-fix
I159-Fix tooltip background was not updated when the theme was changed.
2 parents 0425a9a + 88c9c45 commit a1135f0

18 files changed

+102
-76
lines changed

maui/src/Charts/Behaviors/ChartTooltipBehavior.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
6868
null,
6969
BindingMode.Default,
7070
null,
71-
defaultValueCreator: BackgroundDefaultValueCreator);
71+
null);
7272

7373
/// <summary>
7474
/// Identifies the <see cref="Duration"/> bindable property.
@@ -98,7 +98,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
9898
null,
9999
BindingMode.Default,
100100
null,
101-
defaultValueCreator: TextColorDefaultValueCreator);
101+
null);
102102

103103
/// <summary>
104104
/// Identifies the <see cref="Margin"/> bindable property.
@@ -125,7 +125,7 @@ public partial class ChartTooltipBehavior : ChartBehavior, IParentThemeElement
125125
nameof(FontSize),
126126
typeof(float),
127127
typeof(ChartTooltipBehavior),
128-
14f,
128+
float.NaN,
129129
BindingMode.Default,
130130
null);
131131

@@ -738,16 +738,6 @@ void Tooltip_TooltipClosed(object? sender, TooltipClosedEventArgs e)
738738
return view;
739739
}
740740

741-
static object TextColorDefaultValueCreator(BindableObject bindable)
742-
{
743-
return Color.FromArgb("#F4EFF4");
744-
}
745-
746-
static object BackgroundDefaultValueCreator(BindableObject bindable)
747-
{
748-
return new SolidColorBrush(Color.FromArgb("#1C1B1F"));
749-
}
750-
751741
#endregion
752742

753743
#endregion

maui/src/Charts/ChartBase.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public abstract class ChartBase : View, IContentView, IChart
117117
typeof(ChartBase),
118118
null,
119119
BindingMode.Default,
120+
null,
120121
null);
121122

122123
/// <summary>
@@ -603,7 +604,6 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
603604
continue;
604605
}
605606

606-
SetDefaultTooltipValue(behavior);
607607
var tooltipInfo = chartSeries.GetTooltipInfo(behavior, x, y);
608608
if (tooltipInfo != null)
609609
{
@@ -682,7 +682,6 @@ public void SaveAsImage(string fileName)
682682
if (_defaultToolTipBehavior == null)
683683
{
684684
_defaultToolTipBehavior = new ChartTooltipBehavior();
685-
SetDefaultTooltipValue(_defaultToolTipBehavior);
686685
_defaultToolTipBehavior.Chart = this;
687686
// defaultToolTipBehavior.IsDefault = true;
688687
}
@@ -698,13 +697,6 @@ public void SaveAsImage(string fileName)
698697
}
699698
}
700699

701-
internal void SetDefaultTooltipValue(ChartTooltipBehavior behavior)
702-
{
703-
behavior.Background = TooltipBackground ?? behavior.Background;
704-
behavior.TextColor = TooltipTextColor ?? behavior.TextColor;
705-
behavior.FontSize = !double.IsNaN(TooltipFontSize) ? (float)TooltipFontSize : behavior.FontSize;
706-
}
707-
708700
SfTooltip? IChart.TooltipView
709701
{
710702
get { return _tooltipView; }

maui/src/Charts/Series/BoxAndWhiskerSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,14 +1185,13 @@ internal override void GenerateSegments(SeriesView seriesView)
11851185
Y = yPosition,
11861186
Index = index,
11871187
Margin = tooltipBehavior.Margin,
1188-
TextColor = tooltipBehavior.TextColor,
11891188
FontFamily = tooltipBehavior.FontFamily,
1190-
FontSize = tooltipBehavior.FontSize,
11911189
FontAttributes = tooltipBehavior.FontAttributes,
1192-
Background = tooltipBehavior.Background,
11931190
Item = dataPoint
11941191
};
11951192

1193+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
1194+
11961195
if (IsOutlierTouch)
11971196
{
11981197
tooltipInfo.Text = yValue.ToString();

maui/src/Charts/Series/CartesianSeries.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,14 +1340,14 @@ internal bool IsDataInVisibleRange(double xValue, double yValue)
13401340
Y = yPosition,
13411341
Index = index,
13421342
Margin = tooltipBehavior.Margin,
1343-
TextColor = tooltipBehavior.TextColor,
13441343
FontFamily = tooltipBehavior.FontFamily,
1345-
FontSize = tooltipBehavior.FontSize,
13461344
FontAttributes = tooltipBehavior.FontAttributes,
1347-
Background = tooltipBehavior.Background,
13481345
Text = yValue == 0 ? yValue.ToString("0.##") : yValue.ToString("#.##"),
13491346
Item = dataPoint
13501347
};
1348+
1349+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
1350+
13511351
return tooltipInfo;
13521352
}
13531353

maui/src/Charts/Series/ChartSeries.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,22 @@ internal virtual void GenerateSegments(SeriesView seriesView)
17371737
{
17381738
}
17391739

1740+
/// <summary>
1741+
/// Updates the tooltip appearance including background, text color, and font size.
1742+
///
1743+
/// ChartTooltipBehavior Background with AppThemeBinding · Issue #159 · syncfusion/maui-toolkit
1744+
/// Resolved the issue where tooltip background doesn't update dynamically by changing the theme when using AppThemeBinding.
1745+
/// </summary>
1746+
internal void UpdateTooltipAppearance(TooltipInfo info, ChartTooltipBehavior tooltipBehavior)
1747+
{
1748+
if (Chart is ChartBase chart)
1749+
{
1750+
info.Background = tooltipBehavior.Background ?? chart.TooltipBackground ?? new SolidColorBrush(Color.FromArgb("#1C1B1F"));
1751+
info.TextColor = tooltipBehavior.TextColor ?? chart.TooltipTextColor ?? Color.FromArgb("#F4EFF4");
1752+
info.FontSize = !float.IsNaN(tooltipBehavior.FontSize) ? tooltipBehavior.FontSize : !float.IsNaN((float)chart.TooltipFontSize) ? (float)chart.TooltipFontSize : 14.0f;
1753+
}
1754+
}
1755+
17401756
internal virtual void InitiateDataLabels(ChartSegment segment)
17411757
{
17421758
if (DataLabels.Count > _segments.Count)

maui/src/Charts/Series/HiLoOpenCloseSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ internal virtual void CreateSegment(SeriesView seriesView, double[] values, bool
322322
Index = index,
323323
Text = (yValue == 0 ? yValue.ToString(" 0.##") : yValue.ToString(" #.##")) + "/" + (lowValue == 0 ? lowValue.ToString(" 0.##") : lowValue.ToString(" #.##")) + "/" + (openValue == 0 ? openValue.ToString(" 0.##") : openValue.ToString(" #.##")) + "/" + (closeValue == 0 ? closeValue.ToString(" 0.##") : closeValue.ToString(" #.##")),
324324
Margin = tooltipBehavior.Margin,
325-
TextColor = tooltipBehavior.TextColor,
326325
FontFamily = tooltipBehavior.FontFamily,
327-
FontSize = tooltipBehavior.FontSize,
328326
FontAttributes = tooltipBehavior.FontAttributes,
329-
Background = tooltipBehavior.Background,
330327
Item = dataPoint
331328
};
332329

330+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
331+
333332
return tooltipInfo;
334333
}
335334

maui/src/Charts/Series/PieSeries.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Specialized;
2+
using Microsoft.Maui.Controls;
23
using Syncfusion.Maui.Toolkit.Graphics.Internals;
34

45
namespace Syncfusion.Maui.Toolkit.Charts
@@ -642,15 +643,14 @@ internal override void SetIndividualPoint(object obj, int index, bool replace)
642643
Y = yPosition,
643644
Index = index,
644645
Margin = tooltipBehavior.Margin,
645-
TextColor = tooltipBehavior.TextColor,
646646
FontFamily = tooltipBehavior.FontFamily,
647-
FontSize = tooltipBehavior.FontSize,
648647
FontAttributes = tooltipBehavior.FontAttributes,
649-
Background = tooltipBehavior.Background,
650648
Text = yValue.ToString("#.##"),
651649
Item = dataPoint
652650
};
653651

652+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
653+
654654
return tooltipInfo;
655655
}
656656

maui/src/Charts/Series/PolarSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,13 @@ internal void UpdateAssociatedAxes()
866866
Y = yPosition,
867867
Index = index,
868868
Margin = tooltipBehavior.Margin,
869-
TextColor = tooltipBehavior.TextColor,
870869
FontFamily = tooltipBehavior.FontFamily,
871-
FontSize = tooltipBehavior.FontSize,
872870
FontAttributes = tooltipBehavior.FontAttributes,
873-
Background = tooltipBehavior.Background,
874871
Text = yValue.ToString("#.##"),
875872
Item = dataPoint
876873
};
874+
875+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
877876
return tooltipInfo;
878877
}
879878

maui/src/Charts/Series/RadialBarSeries.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,14 +764,13 @@ internal override void OnSeriesLayout()
764764
Y = yPosition,
765765
Index = index,
766766
Margin = tooltipBehavior.Margin,
767-
TextColor = tooltipBehavior.TextColor,
768767
FontFamily = tooltipBehavior.FontFamily,
769-
FontSize = tooltipBehavior.FontSize,
770768
FontAttributes = tooltipBehavior.FontAttributes,
771-
Background = tooltipBehavior.Background,
772769
Text = yValue.ToString("#.##"),
773770
Item = dataPoint
774771
};
772+
773+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
775774
return tooltipInfo;
776775
}
777776

maui/src/Charts/Series/StackingAreaSeries.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,13 @@ internal override bool IsIndividualSegment()
542542
Y = yPosition,
543543
Index = index,
544544
Margin = tooltipBehavior.Margin,
545-
TextColor = tooltipBehavior.TextColor,
546545
FontFamily = tooltipBehavior.FontFamily,
547-
FontSize = tooltipBehavior.FontSize,
548546
FontAttributes = tooltipBehavior.FontAttributes,
549-
Background = tooltipBehavior.Background,
550547
Text = content.ToString(),
551548
Item = dataPoint
552549
};
553550

551+
UpdateTooltipAppearance(tooltipInfo, tooltipBehavior);
554552
return tooltipInfo;
555553
}
556554

0 commit comments

Comments
 (0)