Silverlight工具包图表:将超链接分配给Axis [英] Silverlight Toolkit Chart: Assign Hyperlink to Axis
问题描述
我有一个简单的Silverlight工具包图表绑定到以下类型的集合:
I have a simple Silverlight Toolkit Chart which is bound to a collection of the following type:
public class ChartItemClass
{
public string Name { get; set; }
public double Value { get; set; }
public string Url { get; set; }
}
我可以得到一个图表来显示名称(X轴)值(Y轴)正确,但我想在X轴上的标签是HyperlinkButtons到Url属性。 X轴标签应该类似如下:
I can get a Chart to display the Name (X-axis) and Value (Y-axis) correctly, but I would like the labels on the X-axis to be HyperlinkButtons to the Url property. The X-axis label should be something like the following:
<HyperlinkButton Content="*Name Property Here*" NavigateUri="*Url Property Here*" TargetName="_blank"></HyperlinkButton>
我发现一个例子允许我为X轴设置AxisLabelStyle,超链接按钮。问题是我不能分配/绑定Url属性作为NavigateUri。任何想法?
I found an example which allowed me to set the AxisLabelStyle for the X-axis so the Labels are now HyperlinkButtons. The problem is I haven't been able to assign/bind the Url property as the NavigateUri. Any ideas?
推荐答案
首先,我将发布完整的代码,然后解释。
At first I will post the complete code and after that the explanation.
<UserControl.Resources>
<Style x:Key="hyperlinkStyle" TargetType="charting:AxisLabel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:AxisLabel">
<HyperlinkButton Content="{Binding Name}" NavigateUri="{Binding Url}" TargetName="_blank"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<charting:Chart>
<charting:Chart.Series>
<charting:ColumnSeries ItemsSource="{Binding Items}" DependentValueBinding="{Binding Value}" IndependentValueBinding="{Binding}">
<charting:ColumnSeries.IndependentAxis>
<charting:CategoryAxis Orientation="X" AxisLabelStyle="{StaticResource hyperlinkStyle}" />
</charting:ColumnSeries.IndependentAxis>
</charting:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
诀窍在这一行:
IndependentValueBinding="{Binding}"
将整个对象传递到独立轴,而不仅仅是属性。
然后,您可以在标签的控制模板中获取绑定对象的属性:
Using this binding you pass a whole object to the independent axis, not just a property. And after that you can get properties of a bound object in the control template of label:
Content="{Binding Name}" NavigateUri="{Binding Url}"
/ code>关键字而不是
TemplateBinding
看起来很奇怪,但它是允许的,它的工作原理。
还有一句话: Url
属性必须包含 http
前缀。它不适用于 www
。
The Binding
keyword instead of the TemplateBinding
looks strange, but it is permitted and it works.
And there is one remark: the Url
property must contain the http
prefix. It doesn't work with www
.
这篇关于Silverlight工具包图表:将超链接分配给Axis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!