Color converter no being called on update

3 posts, 1 answers
  1. svs
    svs avatar
    5 posts
    Member since:
    Sep 2007

    Posted 20 May 2013 Link to this post

    I have a Cartesian chart as follows:

    <telerik:RadCartesianChart x:Name="chart" Grid.Column="0">
        <telerik:RadCartesianChart.Series>
            <telerik:BarSeries ItemsSource="{Binding DataItems}" ValueBinding="Value" CategoryBinding="DayPeriod" >
                <telerik:BarSeries.PointTemplate>
                    <DataTemplate>
                        <Rectangle Fill="{Binding Converter={StaticResource BrushConverter}, ConverterParameter={StaticResource brushes}}"/>
                    </DataTemplate>
                </telerik:BarSeries.PointTemplate>
            </telerik:BarSeries>
        </telerik:RadCartesianChart.Series>
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis Minimum="{Binding MinValue}" Maximum="{Binding MaxValue}" MajorStep="{Binding StepSize}" LabelStyle="{StaticResource axisLabelStyle}" />
        </telerik:RadCartesianChart.VerticalAxis>
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis LabelFitMode="Rotate" LabelInterval="2"/>
        </telerik:RadCartesianChart.HorizontalAxis>
    </telerik:RadCartesianChart>

    I'm setting the colour of each individual Bar in the BarSeries via an IValueConverter (blue for positive, red for negative) using a BrushCollection defined in the UserControl's resources passed into the Value Converted.
    It works very nicely!
    The Chart is bount to an ObservableCollection<t> of items implemention INotofyPropertyChanged. When the values change, the graph does indeed update - but it never calls the Color Converter and it the value goes from - to + or the other way around it ends up with the wrong colour.

    I can't see how to force this update. Is there a way?

    Thanks -



  2. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 23 May 2013 Link to this post

    Hi Simon,

    I think that the only problem is that the binding does not have a Path. The binding does not recall the converter because only a property of the DataPoint has changed and not the whole DataPoint (the DataContext of the Rectangle). I guess that in the Converter you get the Value of the DataPoint, so what you need to do is simply set a Path to the binding and update the converter as needed:
    <telerik:BarSeries.PointTemplate>
     <DataTemplate>
      <Rectangle Fill="{Binding Value, Converter=... />

    Regards,
    Petar Marchev
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. svs
    svs avatar
    5 posts
    Member since:
    Sep 2007

    Posted 23 May 2013 Link to this post

    Petar -

    Thanks very much! You were quite right about what I was doing, and putting the Path in the rectangle did indeed fix it.

    Thank you -

    Simon
Back to Top