1

I am new at WPF and of course I faced some issues with Bindings.

I have initialized RadCartesianChart and I want display data from different type of category lists. For each of those lists I want different color, but I fail to Bind Fill property to my Color property in code behind.

This is how my XAML looks like:

    <telerik:RadCartesianChart Name="RevChart">
        <telerik:RadCartesianChart.Grid>
            <telerik:CartesianChartGrid MajorYLineDashArray="5, 5" MajorLinesVisibility="Y">
                <telerik:CartesianChartGrid.MajorYLineStyle>
                    <Style TargetType="{x:Type Line}">
                        <Setter Property="Stroke" Value="Gray"/>
                    </Style>
                </telerik:CartesianChartGrid.MajorYLineStyle>
            </telerik:CartesianChartGrid>
        </telerik:RadCartesianChart.Grid>
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis />
        </telerik:RadCartesianChart.HorizontalAxis>
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis/>
        </telerik:RadCartesianChart.VerticalAxis>

        <telerik:AreaSeries CategoryBinding="Date" ValueBinding="Rev" Fill="{Binding Color}">

        </telerik:AreaSeries>

    </telerik:RadCartesianChart>

This is my C# code:

public class Revenue
{
    public double Rev { get; set; }
    public DateTime Date { get; set; }
    public Color Color { get; set; }
}

List<Revenue> list = new List<Revenue>();
...
...
this.RevChart.Series[0].ItemsSource = list;

As a results I am getting correct picture, but color is default. So my binding of Color doesn't work. Is it problem in this line Fill={Binding Color} ? Why?

Bill Gates
  • 11
  • 1

1 Answers1

0

Its because Fill is a Brush and you are trying to assign a Color, this wont work.

You will have to assign your Color to the Color property of a SolidColorBrush in the Fill property.

Example

<telerik:AreaSeries CategoryBinding="Date" ValueBinding="Rev">
    <telerik:AreaSeries.Fill>
        <SolidColorBrush Color="{Binding Color}" />
    </telerik:AreaSeries.Fill>
</telerik:AreaSeries>
sa_ddam213
  • 42,848
  • 7
  • 101
  • 110
  • Thanks for your answer! Completely make sense but unfortunately as soon as I add ` .... >` It won't display anything at all just empty chart. – Bill Gates Feb 20 '13 at 00:22
  • I guess you will have to check the `telerik` documentaion and see if they allow this, seems strange that they would not, otherwise you will have to make a `Converter` or make `Color` a `Brush` – sa_ddam213 Feb 20 '13 at 00:30