IndependentValue的绑定颜色

时间:2014-04-17 18:19:26

标签: c# wpf charts

我正在使用WPF图表工具包:System.Windows.Controls.DataVisualization.Charting

我有这样的事情:

<charting:Chart>
    <charting:Chart.Axes>
        <charting:LinearAxis Orientation="Y" />
        <charting:CategoryAxis Orientation="X" />
    </charting:Chart.Axes>

    <charting:ColumnSeries
        IndependentValuePath="RangeText"
        DependentValueBinding="{Binding PercentValue}"
        ItemsSource="{Binding ResultCollection}"/>
</charting:Chart>

与此相关:

ObservableCollection<Result> Results { get; set; }

public Result
{
    public string RangeText { get; set; }
    public float PercentValue { get; set; }
    public bool IsAligned { get; set; }
}

当IsAligned设置为true时,我想要做的是将IndependentValue文本的颜色更改为红色。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

您可以在样式

中进行大量格式化
<Style x:Key="PercentValue" TargetType="{x:Type charting:AxisLabel}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type charting:AxisLabel}">
                <TextBlock Foreground= "Red"  FontSize="8" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<charting:Chart>
    <charting:Chart.Axes>
       <charting:LinearAxis AxisLabelStyle="{StaticResource PercentValue}" Orientation="Y" />
        <charting:CategoryAxis Orientation="X" />
    </charting:Chart.Axes>

    <charting:ColumnSeries
        IndependentValuePath="RangeText"
        DependentValueBinding="{Binding PercentValue}"
        ItemsSource="{Binding ResultCollection}"/>
</charting:Chart>