Defining a LabelDefinition.Template programmatically crashes browser?

2 posts, 0 answers
  1. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 30 Jul 2013 Link to this post


    I have the following situation:

    I am creating a dynamic number of bar/line series using the SeriesProvider class.

    Unfortunately there does not seem to be a way to define a custom label definition within this class so I am waiting until the Loaded event is fired on my chart and trying to do it programmatically.

    RadCartesianChart cartesianChart = chart as RadCartesianChart;
    if (cartesianChart != null)
        // add label definitions since our chart series are created dynamically by Series Providers
        ChartSeriesLabelDefinition cartesianLabelDefintion = new ChartSeriesLabelDefinition();
        // Grab the data template from the resources
        if (Resources.Contains(CartesianLabelTemplateName))
            DataTemplate labelTemplate = Resources[CartesianLabelTemplateName] as DataTemplate;
            if (labelTemplate != null)
                cartesianLabelDefintion.Template = labelTemplate;
        // Default to a property binding if no template is found
        if(cartesianLabelDefintion.Template == null)
            cartesianLabelDefintion.Binding = new PropertyNameDataPointBinding("FormattedValue");
        cartesianChart.Series.ForEach(s =>

    Which results in the following stack trace in Chrome when the chart tries to render.  For some reason I can't intercept this exception in Visual studio.

    Uncaught Error: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Windows.Controls.ChartView.ChartSeries.GetLabelVisual(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.ProcessLabelDefinition(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.ProcessDataPointLabels(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.UpdateLabels(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PointTemplateSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.BarSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.RadChartBase.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.RadChartBase.CallUpdateUI() at Telerik.Windows.Controls.ChartView.RadChartBase.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

    Any thoughts?

  2. Peshito
    Peshito avatar
    522 posts

    Posted 02 Aug 2013 Link to this post

    Hi Colter,

    Wiring to the Loaded event is probably too early for the chart. What I could reccomend is setting the LabelDefinition in XAML. Please take a look at the following demo demonstrating the same approach using ChartSeriesProvider and LabelDefinition:

    Hope this helps.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top