BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
How can i create a Tooltip Template from c sharp code behind ? in the doc's i only found a way todo it in xaml
Hello Andreas,
We have created the data template in the code behind and set it to the series ToolTipTemplate property as shown in the code snippet. We have also attached a sample for your reference.
dataTemplate = new DataTemplate(() => { VerticalStackLayout mainlayout = new VerticalStackLayout(); mainlayout.BackgroundColor = Colors.Black;
HorizontalStackLayout yearLayout = new HorizontalStackLayout(); yearLayout.BackgroundColor = Colors.Black;
Label yearLabel = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White, Text = "Year:" }; Label year = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White}; year.SetBinding(Label.TextProperty, "Item.Year"); yearLayout.Add(yearLabel); yearLayout.Add(year);
HorizontalStackLayout revenueLayout = new HorizontalStackLayout(); revenueLayout.BackgroundColor = Colors.Black;
Label revenueLabel = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White, Text = "Revenue:" }; Label revenue = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White }; revenue.SetBinding(Label.TextProperty, "Item.Revenue", stringFormat: "{0}$"); revenueLayout.Add(revenueLabel); revenueLayout.Add(revenue);
mainlayout.Add(yearLayout); mainlayout.Add(revenueLayout);
return mainlayout; });
areaSeries.TooltipTemplate = dataTemplate; |
Output:
Best Regards,
Raja.
thank you, this works perfectly - maybe you can add this to the doc's as well for others to easily find this
Hi,
You're welcome, Andreas. Currently, we are working on improving our UG, and we will consider your feedback.
Note: If that post is helpful, please mark it as an answer so that other members can locate it more quickly.
Regards,
Preethi R