Getting value of the model in tooltiptemplate of columnseries.

Hi,

I want to use a custom tooltip for my chart, but having problems with it.
I'm able to create a tooltiptemplate and set it on my columnserie. I can access values of my model like this:

var label1 = new Label();
label1.SetBinding(Label.TextProperty, new Binding("XXX"));

But the problem is now that I don't want certain values of my model on a control, but I want to store it in a variable to pass it to some other function when tapping the tooltip.

When looking at the BindingContext in the tooltiptemplate I'm getting my viewmodel back instead of the data model.

So, how can I retrieve values of my data model and place them in a variable?




1 Reply

MP Michael Prabhu M Syncfusion Team August 14, 2018 09:48 AM UTC

Hi Mycna, 
 
Greetings from Syncfusion, we have analyzed your query and it can be achieved by having a converter to the tooltiptemplate text as like in below code snippet. 
  
Code snippet [XAML]:   
<chart:ColumnSeries.TooltipTemplate> 
                                <DataTemplate x:Key="dataMarkerTemplate"> 
                                <StackLayout  BackgroundColor="LightPink" Orientation="Horizontal"> 
                                        <Label  
                                                 FontAttributes="Bold" 
                                                 FontSize="12" 
                                                 Text="{Binding Converter={StaticResource converter}}" 
                                                 TextColor="Blue" 
                                                 VerticalOptions="Center" /> 
                                    </StackLayout> 
                                </DataTemplate> 
                            </chart:ColumnSeries.TooltipTemplate> 
 
  
Code snippet [C#]:    
public class TooltipConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
             if (value != null) 
            { 
                var model = value as Model; 
                //TooltipLabel is another property in data model 
                return model.TooltipLabel + " : " + model.YValue; 
            } 
  
            return value; 
        } 
  
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            return value; 
        } 
    } 
 
  
Based on this we have prepared a sample and it can be downloaded from the link below. 
 
Sample: 139227 
 
Hope this helps. 
 
Thanks, 
Michael 



Loader.
Up arrow icon