diff --git a/MAUI/Cartesian-Charts/display-tooltip-and-data-labels-in-release-mode.md b/MAUI/Cartesian-Charts/display-tooltip-and-data-labels-in-release-mode.md new file mode 100644 index 0000000000..7983de0149 --- /dev/null +++ b/MAUI/Cartesian-Charts/display-tooltip-and-data-labels-in-release-mode.md @@ -0,0 +1,78 @@ +--- +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 +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 +In [SfCartesianChart](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html), tooltip and data label templates do not bind directly to your business model because these elements are generated by the chart at runtime and often represent calculated points. As a result, the chart provides its own binding context containing the necessary metadata. For tooltips this context is [TooltipInfo]https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.TooltipInfo.html), and for data labels it is [ChartDataLabel](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartDataLabel.html). Both expose an Item property that points back to your original business model when a direct mapping exists. With .NET 9 compiled bindings, set **x:DataType="chart:TooltipInfo"** for tooltip templates and **x:DataType="chart:ChartDataLabel"** for data label templates, then bind through Item. If you need a specific field from your model, bind to Item and use a value converter to extract the desired property. + +`Ahead-of-Time (AOT)` compilation converts Intermediate Language to native code at build time to improve startup and runtime performance. AOT commonly ships together with linker trimming in Release configurations to reduce app size. + +Because Release builds enable trimming, members referenced only from XAML can be removed unless explicitly preserved. To ensure your bindings work in Release, reference your value converter from XAML and preserve your ViewModel, business model, and converter types. This prevents the linker from removing properties that your tooltip or data label templates access through Item. + +{% tabs %} + +{% highlight xaml %} + + + + + + + + + + + + + + + + + + + + + +{% endhighlight %} + + +{% highlight C# %} + + public class ValueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is WeekPlan weekPlan ? weekPlan.Planned : value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value; + } + +{% endhighlight %} + +{% endtabs %} + +## See also + +[Why Tooltip and DataLabel Are Missing in Release Mode .NET MAUI Chart?](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 diff --git a/maui-toc.html b/maui-toc.html index 202e289fdb..bcff2bc332 100644 --- a/maui-toc.html +++ b/maui-toc.html @@ -417,6 +417,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 data labels in release mode