Hi, I recently upgraded from 2009.1 to 2009.2 of the Silverlight Data Visualization package.
Code which used to work when modifying axis properties of a xamchart now results in a null reference exception.
eg
slChart.Axes[0].AutoRange = false;
slChart.Axes[0].Maximum = 100;
slChart.Axes[0].Minimum = data.Ymin;
slChart.Axes[0].Unit = 10;
the exception occurs on the first set.
The axis object definitely exists and the properties even have values.
Hi,
I was unable to reproduce your issue with the information provided above. My suggestion is to create a new project with the 9.2 assemblies and copy your code over. If you're still recieving the same exception, can you please reply back with a sample project reproducing the issue.
Also, how did you go about upgrading your project from 9.1 to 9.2?
HI Marisa,
ok I will try to replicate in a smaller clean project.
I upgraded by running the 9.2 installer and deleting the old references in my sl project and adding the new ones in.
I then adjusted my xaml namespaces to 9.2. The xap file correctly contains the 9.2 files..
Thanks,
Ok I have worked out what the problem is and why you can't replicate.
I was modifying the properties of the axis after the axis was added to the xamwebchart.axes collection.
It appears once an axis object is added to the collection, the autorange property and max and min can no longer be changed. (this problem occurs whether the axes is added to collection by code or in xaml markup)
This is definitely introduced after 9.1 and in 9.2
I have worked round it by not adding axes til the last possible moment.
Thanks.
I've attached an application using 9.2 assemblies. The project essentially creates a PrimaryY axis in XAML, and on a button click sets Maximum, Minimum, Unit, and AutoRange = false on the PrimaryY axis. I am unable to reproduce the exception that you are seeing. Can you try this project and see if it is similar to what you're doing?
I'm running into a NullReferenceException as well when trying to modify the axis. I have it defined in xaml and when the data is bound I want to set the min, max, and unit properties to custom values. Anyone figure out what the rules are with setting those values? Do I need to do it in a different spot or do I need to create my axis in code behind?
Thanks for your post. Could you please attach a sample project demonstrating your issue, or supply your code? This will help me better understand what may be going on.
Marisa
In the sample project attached above, the yAxis is not created, it is erroneously assumed to already be in the Axes collection. This is why the NullReferenceException is occuring.
If you run this line:
Axis yAxis = xamWebChart.Axes.FirstOrDefault(a => a.AxisType== AxisType.PrimaryY);
On an empty collection then it will follow that this line raises an exception:
yAxis.AutoRange = false;
If I've misunderstood the situation then please let me know so we can resolve whichever issue you may be having.
-Graham
But what if you're creating charts dynamically (on the fly, without xaml, etc)?
It seems to me that if you create an object, and then tyry to change a public property on said object, and it pukes up a NullReferenceException, if it's not a bug, then it qualifies as piss-poor design.
Kris,
Turns out this isn't a bug and can be easily resolved by creating a PrimaryY axis in XAML. I've re-attached your application with this, and you'll see the null reference exception no longer occurs.
-Marisa
Thanks for your sample application. I was able to reproduce the behavior and have submitted a bug on this, #25754. You can refer to our Developer Support with this bug number for any further information on it.
Thanks,Marisa
I have attached a sample project that illustrates the NullReferenceException that I am encountering. Just open up the solution and hit F5.
-Kris