2014-04-17 100 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>