2014-04-17 58 views
0

我使用WPF图表工具包:System.Windows.Controls.DataVisualization.Charting绑定颜色IndependentValue

我有这样的事情:

<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文本的颜色更改为红色。我怎样才能做到这一点?

+0

格式化使用值转换器 –

+0

如何?___________ – ConditionRacer

+0

我还没有过与图表库工作的很多,但肯定它有一个ItemTemplate,或项容器风格,尝试找到它。它只是一个提示 –

回答

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>