Creating horizontal lines dynamically

Mar 24, 2009 at 6:45 PM
I'm new to C# and WPF so this may just be my lack of experience. I'm trying to add horizontal lines to a chart dynamically but when I do I get the following error: "Object reference not set to an instance of an object". Do I need to use the SetValue() function?

Here's the code:

    HorizontalLine myLine = new HorizontalLine();
    myLine.Value = 1600; //This is where the error occurs

Mar 27, 2009 at 8:52 AM

Can you please make a small application, illustrating the problem you are speaking about, and upload it somewhere?
(You can mail it to me - my email is
This is because the code fragment you've wrote is ok, and problem isn't in it.

From where you a calling code you've given?
Can you post more details about exception? Where does it happen? What reference is null?

Setting value to usual CLR property or using associated with it DependencyProperty in SetValue method are equal, CLR property is made only for developer's convenience.

Apr 15, 2009 at 2:11 AM
Edited Apr 15, 2009 at 2:13 AM
I came across this issue when I attempted to use object initialization syntax.

The following would fail:

var verticalRange = new VerticalRange { Fill = Brushes.Green, Value1 = 10.0, Value2 = 20.0 };

And would work when written as:

var verticalRange = new VerticalRange { Fill = Brushes.Green };
verticalRange.Value1 = 10.0;
verticalRange.Value2 = 20.0;

The issue is that, in the example, the vertical range has to be added to the graph -before- its properties can be set. To my mind, this is a bug.

I'm assuming the same applies to HorizontalLine...

Apr 15, 2009 at 10:21 AM
Hi, Nick and geoffmmorgan!

Thank you for your report, this is really a bug and it is fixed now. So upcoming release of DynamicDataDisplay will not have this bug more.

Mikhail Brinchuk,
DynamicDataDisplay Dev Team.
Apr 16, 2009 at 1:11 AM
That's great!

Thanks :)