Binding error in xaml: Object reference not set to an instance of an object.

Jan 22, 2016 at 8:59 PM
Edited Jan 26, 2016 at 2:59 PM
I follow the example, but visual studio shows an error in xmal file "Object reference not set to an instance of an object." on Graph="{Binding Graph}"
graphViewModel.cs
public Graph<Person> Graph
        {
            get { return _graph; }
            set
            {
                SetProperty(ref _graph, value);
            }
        }
graphViewModel.xaml
<Controls:ZoomControl>
            <WPF:GraphLayout
                UseContentPresenterForAllElements="True"
                LogGraphvizOutput="True"
                Graph="{Binding Graph}"
                >
            </WPF:GraphLayout>
</Controls:ZoomControl>
Coordinator
Jan 26, 2016 at 1:16 AM
Edited Jan 26, 2016 at 1:17 AM
Hi hypertrix,

why do you use dependency property on your ViewModel? You can simply use regular auto-property like in the example:
public Graph<Person> Graph { get; private set; }
Then you also need to set it up with some data. In the example, this is done in the constructor
            var graph = new Graph<Person>();
            var a = new Person(graph) { Name = "Jonh", Avatar = "./Avatars/avatar1.jpg" };
            graph.AddVertex(a);
            // ... etc
            this.Graph = graph;
Jan 26, 2016 at 5:09 PM
Edited Jan 26, 2016 at 5:16 PM
I want to refresh the graph when new data comes in: 1) clear the graph, 2) add vertex and edges based on new data. I didn't find an easy way to clear the graph, so every time I create a new graph and assigned it to Graph.

If I use Graph.RevmoeVertexWithEdges(v), an exception was thrown during layouting.Exception message: An item with the same key has already been added.. Could you shed some light on it? Thanks!
Nov 27, 2016 at 12:58 PM
I'm interested in this last topic as well: How to reload a completely different graph.

Best regards,
Michael Herman (Toronto)