1
我有一個ControlTemplate它包含一個XamWebChart。對於我的系列中創建的每個餅圖切片,我希望它的填充顏色綁定到Value和Label來自的相同源。Infragistics XamWebChart系列填充顏色綁定
我的餅圖目前的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>
綁定到這個控件模板的對象包括:
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到填充屬性的餡餅數據系列。我不知道如何去做這件事。