if you allow me one question regarding dynamically adding vertices (and connected edges).
My problem is that the newly created vertices are all stacked on top of each other (even though the edges are connected correctly to their assigned vertices - which only becomes visible when manually dragging the vertices a bit apart).
I've included a bit of code - hopefully my problem is more abstract and I am simply doing a typical noobish thinking-mistake in the architecture though :-)
I am basically creating an empty graph from my ViewModel and at the same time starting various background-workers which load rdf-data from different sources.
The background workers fill a singleton (thread-safe) collection object (EntityCache). When the workers finish the workerCompleted method in the main UI thread triggers a refreshGraph(..) which adds newly added model objects as new vertices to the graph:
private void refreshGraph (object sender, NotifyCollectionChangedEventArgs eventArgs)
// handle added items
if (eventArgs.Action == NotifyCollectionChangedAction.Add)
foreach (EntityViewModel newEntityViewModel in eventArgs.NewItems)
// request relayout from the view
/// Adds an entity to the graph.
/// <param name="entity">The entity.</param>
private void addEntityViewModelToGraph(EntityViewModel entityViewModel)
if (entityViewModel != null)
//// create a new EntityViewModel from this entity (or get from cache)
entityViewModel = this.getCachedEntityViewModel(entityViewModel);
// now check if there are references in object-properties we can add too
Dictionary<string, object> properties = entityViewModel.entity.GetAllProperties();
foreach (KeyValuePair<string, object> kvpProperty in properties)
// check if it is an object property
Property propertyType = entityViewModel.entity.GetPropertyType(kvpProperty.Key);
// if the object property is a list of entities add all
if (kvpProperty.Value.GetType() ==
foreach (IEntity connectedEntity in (IList<IEntity>)kvpProperty.Value)
// create a new EntityViewModel from this entity (or get cached)
EntityViewModel connectedEntityViewModel =
Edge<EntityViewModel> e2 = new Edge<EntityViewModel>(entityViewModel,
// raise property changed to View
When the vertices ended up all stucked up I tried to manually force a relayout of the graphControl in the view by raising an event from viewModel to view.
(As you can see in the first method (last statement)).
This unfortunately led to the following exception in FSAAlgorithms.cs:HorizontalImproved()
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at GraphSharp.Algorithms.OverlapRemoval.FSAAlgorithm`2.HorizontalImproved() in D:\ConSenseCode\ConSense\_foreignSvn\GraphSharp\Graph#\Algorithms\OverlapRemoval\FSAAlgorithm.cs:line 164
at GraphSharp.Algorithms.OverlapRemoval.FSAAlgorithm`2.RemoveOverlap() in D:\ConSenseCode\ConSense\_foreignSvn\GraphSharp\Graph#\Algorithms\OverlapRemoval\FSAAlgorithm.cs:line 35
at GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalAlgorithmBase`2.InternalCompute() in D:\ConSenseCode\ConSense\_foreignSvn\GraphSharp\Graph#\Algorithms\OverlapRemoval\OverlapRemovalAlgorithmBase.cs:line 48
at GraphSharp.Algorithms.AlgorithmBase.Compute() in D:\ConSenseCode\ConSense\_foreignSvn\GraphSharp\Graph#\Algorithms\AlgorithmBase.cs:line 36
[.. left the rest of the stacktrace out]
Really at a loss at what to do here.
I could imagine the two problems are a bit unrelated with the second being due to some threading problem in my architecture, but the first?
Why isnt the graph just laying out the newly added vertices correctly - I mean obviously updating the ViewModel gets noticed by the graphControl, as there ARE vertices shown in the first place.
Cheers and thank you a bunch for any input on this,