I use function ObservableCollection in one class.
It is defined public to be reachable in another class also.
public ObservableCollection<Node> _nodes;
public ObservableCollection<Node> Nodes
{
get { return _nodes ?? (_nodes = new ObservableCollection<Node>()); }
}
I want to call this ObservableCollection in another class, how to do it correctly?
I try already with this topic on stackoverflow, but shows me that Node is empty.
So you have your Class A, which contains your "nodes".
To access the nodes from Class B a few things need to happen:
In Class B, you must instantiate a Class A:
That will give you access to ClassA's public Nodes property.
Another note - it seems like you are using a getter/setter, but in that case your first
could be changed to
to properly encapsulate it. Then you could add a setter to your public property (unless it is readonly):