[英]Silverlight Chart data binding to ControlTemplate
I'm not sure if this can be done, but I've got a BubbleSeries with a custom ControlTemplate for the DataPointStyle. 我不确定是否可以做到这一点,但是我有一个BubbleSeries,带有一个DataPointStyle的自定义ControlTemplate。 I want to add some text to the bubble, but I can't seem to get the data binding working. 我想在气泡中添加一些文本,但似乎无法使数据绑定正常工作。 I want to bind a TextBlock to the "Name" value in the object I've bound to. 我想将TextBlock绑定到我绑定到的对象中的“名称”值。 Hopefully the code should explain: 希望代码可以解释:
<Style x:Key="BubbleItemTemplate" TargetType="toolkit:BubbleDataPoint">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:BubbleDataPoint">
<Viewbox x:Name="viewbox">
<Border>
<Grid>
<TextBlock Text="{TemplateBinding Name}" />
</Grid>
</Border>
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and the ItemSource is 并且ItemSource是
public void AddData(List<ChartItem> items)
{
List<Dictionary<string, object>> gridData = new List<Dictionary<string, object>>();
foreach (var i in items)
{
gridData.Add(CreateBubbleEntry(i.XAxis, i.YAxis, i.ZAxis, i.Title));
}
_bubbleView.ItemsSource = gridData;
}
private Dictionary<string, object> CreateBubbleEntry(double independent, double dependent, double size, string title)
{
var item = new Dictionary<string, object>();
item.Add("independent", independent);
item.Add("dependent", dependent);
item.Add("size", size);
item.Add("Name", title);
return item;
}
Thanks 谢谢
Try replacing: {TemplateBinding Name}
with {Binding Name}
尝试将{TemplateBinding Name}
替换为{Binding Name}
That should do the trick. 这应该够了吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.