- Home
- Forum
- Silverlight
- Identify the Shapes Dropped on the Page from the Palette
Identify the Shapes Dropped on the Page from the Palette
Hi Chris Goodwin,
Internal behavior:
When the symbol is dropped from the SymbolPalette, the Content of the Symbol is serialized. In DiagramView OnDrop event, this serialized object will be desterilized to create a clone of SymbolPaletteItem’s Content. Next a new node will be created and the cloned object will be set as a Node’s content.
Determine
which node is dropped:
To identify which Symbol has been dropped, Name property of the
SymbolPaletteItem can be used to achieve this requirement. SymbolPaletteItemName
property in NodeDrop event returns the Name of the dropped SymbolPaletteItem.
We have provided a code snippet to represent this ,please refer to the code
snippet.
Code Snippet:
//Creating SymbolPaletteItem
SymbolPaletteItem item = new SymbolPaletteItem();
item.Width = 40;
item.Height = 20;
//Used for Identifying the Dropped Node
item.Name = 'shape1';
//spg1 is SymbolPalette group
spg1.Items.Add(item);
//Register the NodeDrop event of DiagramView
diagramView.NodeDrop += new NodeDroppedEventHandler(diagramView_NodeDrop);
//DiagramView
NodeDrop Event
void diagramView_NodeDrop(object sender, NodeDroppedRoutedEventArgs evtArgs)
{
if (evtArgs.SymbolPaletteItemName == 'shape1')
{
//Reference of the Dropped Node using evtArgs
Node dropNode = evtArgs.DroppedNode as Node;
}
}
Please let us know if you have any concerns
Regards,
MohanaPriya R
My name is Chase Novack. I work on the same development team as Chris Goodwin, and since he is out of the office this week, I'm looking into this issue.
The code you posted would be a great solution if we wanted to perform our event (opening a child window with relevant data from the database) on NodeDrop, but we want to be able to do this on NodeClick instead. Is there any way for us to access the Tag or Name property of a SymbolPaletteItem inside the NodeClick event that corresponds to the SymbolPaletteItem that is dropped onto the diagram?
Thanks for your help,
Chase
Hi Chase Novack,
Regarding “Access the Tag or Name property of a SymbolPaletteItem inside the NodeClick event” To identify which Symbol has been dropped, Your requirement can be achieved by using NodeDrop event of DiagramView and Tag property of Node. Please use the Tag property of the Node to save the SymbolPaletteItemName property in NodeDrop Event. We have provided code snippet to achieve your requirement. Please refer to the following code snippet.
Code Snippet:
//DiagramView NodeDrop Event
void diagramView_NodeDrop(object sender, NodeDroppedRoutedEventArgs evtArgs)
{
if (evtArgs.SymbolPaletteItemName == 'shape1')
{
//Reference of the Dropped Node using evtArgs
Node dropNode = evtArgs.DroppedNode as Node;
dropnode.Tag="shape1";
}
}
//DiagramView NodeClick Event
void diagramView_NodeClick(object sender, NodeRoutedEventArgs evtArgs)
{
Node dropnode = evtArgs.Node as Node;
//use the Tag property of Node to identify the Clicked Node
}
Please let us know if you have any concerns
Regards,
MohanaPriya R
This is closer to what we need but I don't think using NodeDrop at all will work for us. We create our custom SymbolPaletteItems from the database using a loop like this in the constructor of a user control (we also assign the loop index to the tag property in the loop):
Thanks.
Node item = sender as Node;
int equipIndex = (int)item.Tag;
Hi Chase,
Thanks for your update.
Please let us know if you require further assistance
on this.
Regards,
Saranya C
- 7 Replies
- 4 Participants
-
CG Chris Goodwin
- Aug 7, 2014 09:10 PM UTC
- Aug 20, 2014 04:24 AM UTC