diff --git a/maui-toolkit-toc.html b/maui-toolkit-toc.html index be427528..86040038 100644 --- a/maui-toolkit-toc.html +++ b/maui-toolkit-toc.html @@ -168,6 +168,7 @@
  • Add custom labels to the chart axis
  • Customize each chart axis label using the callback event
  • Get the data point collection based on region
  • +
  • Display tooltip and datalabels in release mode
  • diff --git a/maui-toolkit/Cartesian-Charts/Display-tooltip-datalabels-in-release-mode.md b/maui-toolkit/Cartesian-Charts/Display-tooltip-datalabels-in-release-mode.md new file mode 100644 index 00000000..d87ee1d7 --- /dev/null +++ b/maui-toolkit/Cartesian-Charts/Display-tooltip-datalabels-in-release-mode.md @@ -0,0 +1,73 @@ +--- +layout: post +title: Show tooltip and datalabels in release mode | Syncfusion +description: Learn here all about displaying tooltip and datalabels in release mode in SfCartesianChart in Syncfusion® .NET MAUI Chart (SfCartesianChart) control. +platform: maui-toolkit +control: SfCartesianChart +documentation: ug +keywords: .NET MAUI chart tooltip, .NET MAUI chart data label, TooltipInfo Item binding, ChartDataLabel Item binding, Release mode trimming, Preserve attribute MAUI. +--- + +# Display tooltip and data labels in release mode + +The binding context inside tooltip and data labels templates is not your model directly. These templates run in the scope of [TooltipInfo](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.TooltipInfo.html) and [ChartDataLabel](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartDataLabel.html), which expose an `Item` property that contains the actual data model from the charts [ItemsSource](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_ItemsSource). To read your model’s fields in a template, bind through Item or use a converter. + + +With .NET 9 compiled bindings, tooltip templates run with **x:DataType="chart:TooltipInfo"** and data label templates run with **x:DataType="chart:ChartDataLabel"**. Inside these templates, bind to the model via the Item property. Use a value converter to pull the required field from Item. In Release builds, trimming/AOT can remove XAML-only types, so preserve your ViewModel, Model, and the converter to keep these bindings working. + + +{% highlight xaml %} + + + ..... + + + + + + + + + + + + + + + + +{% endhighlight %} + + +{% highlight C# %} + + public class TooltipConverter : IValueConverter + { + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + // value is TooltipInfo.Item or ChartDataLabel.Item -> your Model + if (value is Model model && parameter?.ToString() == "Planned") + return model.Planned; + + return value; + } + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => value; + } + +{% endhighlight %} + +## See also + +[How to display tooltip and data labels in release mode .NET MAUI SfCartesianChart](https://support.syncfusion.com/kb/article/21677/why-tooltip-and-datalabel-are-not-showing-in-release-mode-in-net-maui-sfcartesianchart) \ No newline at end of file