I have a NodeTemplateDictionary and a GroupTemplate but even if the property of my node IsSubGraph is set to true, my group takes the default NodeTemplate instead of the GroupTemplate. I set the paths in my model like this:
I did exactly the same as what it says in the Introduction to GoXam and I have no idea what can be wrong. Here is a screenshot where I bind the Key, SubGraphKey and IsSubGraph property to my node. Everything seems ok but my Group still take the NodeTemplate.
And here is how I defined my NodeTemplate and GroupTemplate:
Might you have changed your node data’s IsSubGraph property after the node data had been added to the model? GoXam assumes that that property value never changes. So a regular Node DataTemplate will have been applied before it knows that it’s supposed to be a Group.
That wouldn’t change how it appeared – it should still be some text above a green-bordered rounded rectangle. If it didn’t have any members, it would still be 10x10 big.
I suppose you could override GraphLinksModel.FindIsGroupForNode to set a breakpoint to see what it returns for each node data.
PartManager.FindCategoryForNode doesn’t return the right Category. And another thing, the “isGroup” parameter is true then it should be false.
Same in the PartManager.FindTemplateForNode and PartManager.MakeNodeForData, parameter “isGroup” is false.
If I manually return the right Category and set the isGroup parameter to the right value, it works but my nodes are not embedded in my group (see picture below).
And yes, I overrided methods in GraphLinksModel:
FindToNodeKeyForLink/FindFromNodeKeyForLink where I manually return the FromKey instead of calling the base class method
InsertLink where I manually add the link to the LinksSource instead of calling the base class method
MakeNodeKeyUnique Return true all the time except when the nodedata parameter is null
ModifyLinkFromPort/ModifyLinkToPort I don't think this method is the cause of my problem
Are you saying that PartManager.FindCategoryForNode is being called on a node data that should be considered to be a group but the “isGroup” argument is false when it should be true? Well, that would explain the behavior. Now we need to figure out why that argument is false.
To review the whole process, including things you can check:
GraphLinksModel.FindIsGroupForNode is called once to determine if the node data “is a group”; this value is remembered
GraphLinksModel.GetIsGroupForNode is called, possibly many times, to decide if the model thinks the node data “is a group”. This returns the value remembered from the call to FindIsGroupForNode, which is why one cannot change the value dynamically. This is called by…
PartManager.AddNodeForData which passes the value from GetIsGroupForNode to the various methods that I mentioned before (FindCategoryForNode, FindTemplateForNode). But in your case it’s too late – the value is wrong. So further investigation of all three of these methods is unnecessary.
My guess is that GraphLinksModel.GetIsGroupForNode is returning the wrong value because it appears to have changed. Might there be a duplicate key? That would really cause confusion.
And you need to check whether the node data have the same key as their “group key”. The methods are GraphLinksModel.GetGroupForNode and FindGroupKeyForNode.
If FindGroupKeyForNode is returning the “wrong” value, null, initially, that implies that you are modifying the node’s state to give it a reference to the group data, via its key. Are you calling SetGroupNodeKey to do that, or does the property setter call RaisePropertyChanged? If neither is true, the model won’t know that the value of FindGroupKeyForNode will have changed.
Maybe you should create all of your node data before you add them to the model by assigning the NodesSource collection.
No, FindGroupKeyForNode returns the right value the first time because the group is not yet created. But when I create the group, FindGroupKeyForNode is not called a second time for the nodes, even if the SubGraphKey property of my nodes have changed. That’s why I asked you if FindGroupKeyForNode is only called once for each node.
And no I didn’t call SetGroupNodeKey to nofity model that the SubGraphKey changed. I tried, and directly after, I called GetIsGroupForNode but this method returns again false.
Does your node data class implement INotifyPropertyChanged and does its SubGraphKey property setter call RaisePropertyChanged (and only if the value has actually changed)?
If the data is part of the model, the model’s PropertyChanged event handler for that data will be called with a property change using the name “SubGraphKey”. If that matches the GraphLinksModel.GroupNodePath, then the model knows that the data is changing its group membership.
If the data is not (yet) part of the model, then nothing happens until the data is added to the model.
In either case GraphLinksModel.FindGroupKeyForNode will be called, so that the model can find and remember any group that it’s supposed to be a member of.
It was because I was overriding the GraphLinksModelNodeData.OnPropertyChanged whitout calling the base class method or without raising the property changed event. I feel so stupid right now :P