Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm using the DataVisualization namespace in the Silverlight Toolkit. I'm trying to figure out how to create a custom tooltip. I've overridden the datapoint template, and I know where to do what I want to do, but not exactly how to go about doing it.

Essentially, I want to show the series title, the FormattedIndependentValue (X-Axis label for the datapoint), and the datapoint value. The only thing I don't know how to get to is the series title.

The part of the template that matters is here:

<ToolTipService.ToolTip>
    <StackPanel>
 
        <ContentControl Content="{Binding ????????}" />
 
        <ContentControl Content="{TemplateBinding FormattedIndependentValue}" />
        <ContentControl Content="{Binding Value, Converter={StaticResource DataValueConverter}}" />
    </StackPanel>
</ToolTipService.ToolTip>


My question is what to bind to for the ContentControl shown by the "???????"?

The chart contains a collection of Series, each of which contains a collection of datapoints. The datapoint template contains the tooltip XAML shown above.

The property I'm after is mainChart.Series[n].Title. How do I get there?
Posted
Updated 22-Feb-11 2:10am
v6

1 solution

01/17/2011 08:00 (SOLUTION)
===========================================================================
ATTENTION! Please do not delete this as I am testing Codeproject site
functionality regarding posting solutions to your own questions. Many
thanks.
===========================================================================

Well, I haven't been able to find anything that will let me do it that way, so I added a property to the DataPointSeries items called ParentChartSeries, and after the series is created, I call a method in my page that sets this property, like so:

C#
foreach (DBSeriesDataItem item in series.ItemsSource)
{
   item.ParentChartSeries = series;
}


After that, I could do this in the XAML:

<ContentControl Content="{Binding ParentChartSeries, Converter={StaticResource TooltipTitleConverter}}" /> 


Here's the TooltipTitleConverter defined in the XAML:

<local:BudgetPanelBase.Resources>
    <local:TooltipTitleConverter x:Key="TooltipTitleConverter" />
</local:BudgetPanelBase.Resources>


And finally, the code for the converter:

C#
public class TooltipTitleConverter : IValueConverter
{
//-------------------------------------------------------------------------
public object Convert(Object value, System.Type targetType, Object parameter, System.Globalization.CultureInfo culture)
{
    Label label = null;
    if (value != null)
    {
        MSChart.DataPointSeries series = value as MSChart.DataPointSeries;
        label = new Label();
        label.Content = series.Title;
    }
    return obj;
}
 
//-------------------------------------------------------------------------
public object ConvertBack(Object value, System.Type targetType, Object parameter, System.Globalization.CultureInfo culture)
{
    return value;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900