This is a migrated thread and some comments may be shown as answers.

NullReferenceException on Axis.CreateLabelTextBlock when NoXaml dll

4 Answers 48 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 15 May 2018, 07:29 AM

Hi,

I have a small project that worked fine when referencing regular telerik dll.

Now I try to reference NoXaml dll, with the attached merged dictionary picture, the program fails on a NullReferenceException in Axis.CreateLabelTextBlock().

(Attached Call Stack)

After digging into it, I noticed that the exception occurs only when I write a style targetting telerik:LinearAxis local to my window.

Thanks for the help.

Benn.

 

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 15 May 2018, 01:37 PM
Hello Ben,

Thank you for the provided information. I was able to reproduce the exception. This happens because the style probably is missing the BasedOn attribute. Because of this the default implicit style of the axis is overridden including its ControlTemplate. On the other hand the CreateLabelTextBlock() method depends on the elements in the template and the error gets thrown when they are not presented.

To resolve this you can base the custom LinearAxis Style to the default one of the control. Note that you should do this for any custom Style that targets Telerik control in a NoXaml scenario.
<Window.Resources>
    <Style TargetType="telerik:LinearAxis" BasedOn="{StaticResource AxisStyle}">
        <Setter Property="Opacity" Value="0.5" />
    </Style>
</Window.Resources>
I hope that helps.


Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
BENN
Top achievements
Rank 1
answered on 16 May 2018, 04:57 AM

You are correct. Adding the BasedOn does solves the crash, but nothing is being shown on the chart.

 

Since the chart does not support series by binding (the number of curves changes by the loaded data), then it is being added by code, for example:

foreach (var curve in (DataContext as SamplingWindowModelBase).CurveLivingProperties)
{
LinearAxis verticalAxis = new LinearAxis();
verticalAxis.DataContext = curve;
verticalAxis.SmartLabelsMode = AxisSmartLabelsMode.SmartStep;

LineSeries curveLine = new LineSeries();
curveLine.DataContext = curve;
curveLine.VerticalAxis = verticalAxis;
chart1.Series.Add(curveLine);
}

 

 

When referencing the regular dlls, then I can see the series, but when referencing the NoXaml dlls and using the styles as shown on my first post (even when the LinearAxis I added is being commented), the chart shows "No data to plot".

 

Why?

0
Accepted
Martin Ivanov
Telerik team
answered on 17 May 2018, 07:02 AM
Hello Benn,

In order to show the LineSeries you will also need to set its ItemsSource, CategoryBinding and ValueBinding properties. Check the Create Data-Bound Chart article to see how to do this in code-behind.

Additionally, the chart supports dynamic number of series create via custom models. You can read more about this in the Dynamic Number of Series article.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
BENN
Top achievements
Rank 1
answered on 21 May 2018, 05:12 AM

Hi,

Using the ChartSeriesProvider indeed solved the problem!

Thanks

Tags
ChartView
Asked by
BENN
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
BENN
Top achievements
Rank 1
Share this question
or