Palette Node and Diagram Node ViewModel Conflict

Hi,

Recently I encountered an issue with my OrgChart application.

I have a Palette on left pane whose view model is OrgChartNodeData and Diagram on right whose view model is OrgChartNodeData. That means both have same view model but with different views. Plus I have created a CustomDraggingTool by extending your DraggingTool.

I drag a node(Source) from Palette and drop it onto a node(Target) in Diagram that’s in right pane. At UI level I can see that a new node(Child) has been added as Target’s child node. Logically the Child Node’s DataContext (OrgChartNodeData) has nothing to do with Source Node’s DataContext (OrgChartNodeData). But when I fire any command from Child node, it executes the Command defined in Source Node’s datacontext.

Do you have any idea what could be the possible reason. I am using TreeModel and everything is in Silverlight 4.

Thanks!!

It sounds like the copied node data still has a reference to the source model or palette somehow.

Are you copying event handlers? They probably have implicit references to where they were defined.

Or maybe some copied functional properties are closures referring to objects in the palette’s environment?

Tracking down unintended shared references can be tricky in the debugger. It might help to make sure your classes have some easily seen unique identifiers.

I have implemented one of your methods IsOK()

This is what I have done in it:

string parentcode = draggedOntoNodeData.NodeCode;
int parentKey = draggedOntoNodeData.Key;
int sectionID = draggedOntoNodeData.NodeSectionId;
if (draggedParts != null)
{
foreach (Part part in parts)
{
if (part.Layer.ToString() != “Northwoods.GoXam.LinkLayer”)
{
var draggingNodeData = ((OrgChartNode)part.Data);
var lappNodesInChart = from lappNode in this.Diagram.Nodes
where ((OrgChartNode)lappNode.Data).NodeCode == draggingNodeData.NodeCode
select lappNode;

                        if (lappNodesInChart.Count() > 0)
                        {
                            Node lappNode = (lappNodesInChart.ToList())[0];
                            OrgChartNode lappNodeData = lappNode.Data as OrgChartNode;
                            lappNodeData.ParentNodeCode = parentcode;
                            if (draggedOntoNodeData.Key == 0)
                            {
                                if (lappNodeData.LevelId != 0)
                                {
                                    lappNodeData.NodeSectionId = 0;
                                }
                            }
                            else
                            {
                                lappNodeData.NodeSectionId = sectionID;
                            }

                            if (isDroppedFromPalette)
                            {
                                lappNodeData.NodeCode = Guid.NewGuid().ToString();
                                lappNodeData.ParentKey = parentKey;
                                lappNodeData.SequenceNumber = lappNodeData.Key + 1;
                                lappNodeData.IsHidden = 0;
                            }
                        }
                    }
                }
            }

Can you please tell me if there’s anything that I have mistakenly implemented or left to be implemented.

Thanks!!

The method above IsOk has following signature:

public bool IsOk(Node node, Dictionary<Part, DraggingTool.Info> draggedParts, bool isDroppedFromPalette)
{ … }