为IndependentValue绑定颜色
本文关键字:颜色 绑定 IndependentValue | 更新日期: 2023-09-27 17:58:45
我正在使用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文本的颜色更改为红色。我该怎么做?
您可以在样式中进行大量格式化
<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>