[已解决] Silverlight.ToolKit.DataVisualization数据点工具提示中的绑定 [英] [SOLVED] Binding in Silverlight.ToolKit.DataVisualization Datapoint Tooltip
问题描述
我正在使用Silverlight Toolkit中的DataVisualization命名空间.我试图弄清楚如何创建自定义工具提示.我已经覆盖了数据点模板,并且我知道该在哪里做我想做的事情,但不知道该怎么做.
本质上,我想显示系列标题,FormattedIndependentValue
(数据点的X轴标签)和数据点值.我唯一不知道如何到达的是系列名称.
模板的重要部分在这里:
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>
我的问题是要为"???????"所示的ContentControl
绑定什么?
图表包含系列的集合,每个系列都包含数据点的集合.数据点模板包含上面显示的工具提示XAML.
我想要的属性是mainChart.Series[n].Title
.如何到达那里?
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?
推荐答案
2011/01/17 08:00(解决方案)
================================================== =======================
注意力!请不要删除它,因为我正在测试Codeproject网站
有关发布针对您自己的问题的解决方案的功能.许多
谢谢.
================================================== =======================
好吧,我找不到任何可以让我那样做的东西,所以我在DataPointSeries
项中添加了一个名为ParentChartSeries
的属性,在创建系列后,我在自己的方法中调用了一个方法设置此属性的页面,如下所示:
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 theDataPointSeries
items calledParentChartSeries
, and after the series is created, I call a method in my page that sets this property, like so:
foreach (DBSeriesDataItem item in series.ItemsSource)
{
item.ParentChartSeries = series;
}
之后,我可以在XAML中执行此操作:
After that, I could do this in the XAML:
<ContentControl Content="{Binding ParentChartSeries, Converter={StaticResource TooltipTitleConverter}}" />
这是XAML中定义的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:
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;
}
这篇关于[已解决] Silverlight.ToolKit.DataVisualization数据点工具提示中的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!