How to Bind ValueBinding Property of a Series by Using CategoricalSeriesDescriptor

Environment

Product Version 2019.3.917
Product RadChartView for WPF

Description

How to DataBind ValuePath of CategoricalSeriesDescriptor.

Solution

As the ValuePath property cannot be data bound what we need do instead is use the Style property of the descriptor to bind the ValueBinding property of the series.

  1. In the code-behind we need to create a StringToValuePathConverter like so:

        public class StringToValuePathConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            var valuePath = value.ToString(); 
            return new PropertyNameDataPointBinding(valuePath); 
        } 
     
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        } 
    } 
    
  2. In XAML use a ValueBinding property of a series with an IValueConverter. To do that use the Style property of the CategoricalSeriesDescriptor like so:

         <telerik:ChartSeriesProvider.SeriesDescriptors> 
                                    <telerik:CategoricalSeriesDescriptor x:Name="seriesDescriptor" CategoryPath="ArchiveTime"         
                                                                 ItemsSourcePath="ChartItems"> 
                                            <telerik:CategoricalSeriesDescriptor.Style> 
                                                <Style TargetType="telerik:BarSeries"> 
                                                    <Setter Property="ValueBinding" Value="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadCartesianChart}, Path=DataContext.BarChartValuePath, Converter={StaticResource StringToValuePathConverter}}" /> 
                                                </Style> 
                                            </telerik:CategoricalSeriesDescriptor.Style> 
                                    </telerik:CategoricalSeriesDescriptor> 
        </telerik:ChartSeriesProvider.SeriesDescriptors> 
    
In this article
Not finding the help you need? Improve this article