Infragistics XamWebChart 系列填充颜色绑定
我有一个包含 XamWebChart 的 ControlTemplate。对于我的系列中创建的每个饼图切片,我希望其填充颜色绑定到值和标签的同一来源。
我的饼图的当前 xaml 如下所示:
<ControlTemplate x:Key="DataLocation">
<Viewbox
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Stretch="Fill">
<Grid>
<Grid.Resources>
<Style x:Key="PieChartSeriesStyle" TargetType="Chart:Series">
<Setter Property="Stroke" Value="#00FFFFFF" />
<Setter Property="Marker">
<Setter.Value>
<Chart:Marker Foreground="#FFFFFFFF" />
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Chart:XamWebChart x:Name="PieChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Chart:XamWebChart.Scene>
<Chart:Scene>
<Chart:Scene.GridArea>
<Chart:GridArea BorderThickness="0" Background="#00FFFFFF" />
</Chart:Scene.GridArea>
</Chart:Scene>
</Chart:XamWebChart.Scene>
<Chart:XamWebChart.Series>
<Chart:Series
ChartType="Pie"
Style="{StaticResource PieChartSeriesStyle}"
DataMapping="Value=Amount;Label=Identifier"
DataSource="{Binding Path=ToolTip.Details}"
Fill="{Binding DetailItem.ColorProvider.BackgroundColor}">
</Chart:Series>
</Chart:XamWebChart.Series>
</Chart:XamWebChart>
</Grid>
</Viewbox>
</ControlTemplate>
绑定到此 ControlTemplate 的对象是:
public sealed class GeographyDataItem{
public IEnumerable<GeographyDataDetailItem> Details
{
get { return _details; }
}
}
带子项:
public sealed class GeographyDataDetailItem
{
private readonly IColorProvider _colorProvider;
public IColorProvider ColorProvider
{
get { return _colorProvider; }
}
public string Identifier { get; private set; }
public double Amount { get; private set; }
public GeographyDataDetailItem(string identifier, double amount, IColorProvider colorProvider)
{
_colorProvider = colorProvider;
Identifier = identifier;
Amount = amount;
}
}
其中 IColorProvider 是:
public interface IColorProvider
{
Color ForegroundColor { get; }
Color BackgroundColor { get; }
}
ControlTemplate 绑定设置为绑定到 GeographyDataItem 元素。
我遇到的唯一问题是绑定 GeographyDataDetailItem 的 ForegroundColor 属性。 IColorProvider 到饼图数据系列的 Fill 属性。我不知道该怎么做。
I have a ControlTemplate that contains a XamWebChart. For each pie slice created in my series, I would like its fill color bound to the same source the Value and Label are coming from.
The current xaml for my pie chart looks like:
<ControlTemplate x:Key="DataLocation">
<Viewbox
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Stretch="Fill">
<Grid>
<Grid.Resources>
<Style x:Key="PieChartSeriesStyle" TargetType="Chart:Series">
<Setter Property="Stroke" Value="#00FFFFFF" />
<Setter Property="Marker">
<Setter.Value>
<Chart:Marker Foreground="#FFFFFFFF" />
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Chart:XamWebChart x:Name="PieChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Chart:XamWebChart.Scene>
<Chart:Scene>
<Chart:Scene.GridArea>
<Chart:GridArea BorderThickness="0" Background="#00FFFFFF" />
</Chart:Scene.GridArea>
</Chart:Scene>
</Chart:XamWebChart.Scene>
<Chart:XamWebChart.Series>
<Chart:Series
ChartType="Pie"
Style="{StaticResource PieChartSeriesStyle}"
DataMapping="Value=Amount;Label=Identifier"
DataSource="{Binding Path=ToolTip.Details}"
Fill="{Binding DetailItem.ColorProvider.BackgroundColor}">
</Chart:Series>
</Chart:XamWebChart.Series>
</Chart:XamWebChart>
</Grid>
</Viewbox>
</ControlTemplate>
The objects that are Bound to this ControlTemplate are:
public sealed class GeographyDataItem{
public IEnumerable<GeographyDataDetailItem> Details
{
get { return _details; }
}
}
With children:
public sealed class GeographyDataDetailItem
{
private readonly IColorProvider _colorProvider;
public IColorProvider ColorProvider
{
get { return _colorProvider; }
}
public string Identifier { get; private set; }
public double Amount { get; private set; }
public GeographyDataDetailItem(string identifier, double amount, IColorProvider colorProvider)
{
_colorProvider = colorProvider;
Identifier = identifier;
Amount = amount;
}
}
Where IColorProvider is:
public interface IColorProvider
{
Color ForegroundColor { get; }
Color BackgroundColor { get; }
}
The ControlTemplate binding is set to bind to GeographyDataItem elements.
The only issue I am having is binding the ForegroundColor property of GeographyDataDetailItem . IColorProvider to the Fill property of the Pie Data Series. I am not sure how to go about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法在 XAML 中实现我想要的目标,但能够在控制代码隐藏中支持此用例。
我的解决方案是:
代码如下:
因此,现在每次加载 XamWebChart 进行渲染时,都会从数据源应用填充颜色。绑定侦听属性更改是没有必要的,因为我不希望颜色在渲染后发生变化。
如果知道在 XAML 中使用此方法以减少此代码隐藏的替代方案,那就太好了;不过,暂时这解决了我的问题。
I was unable to achieve what I wanted in XAML, but was able to support this use case in the control code-behind.
My solution is:
And the Code beind:
So, now each time a XamWebChart is loaded for render, the Fill color is applied from the data source. Binding listening to property changes is not necessary as I do not expect the color to change following the render.
It would be nice to know an alternative to have this in XAML, to reduce this code-behind; however, for the time being this solved my problem.