Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Need to hold values with node (Read 8341 times)
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Need to hold values with node
Aug 8th, 2011 at 12:27pm
Print Post  
HI,
In my application While double clicking on node, one window gets popup, where i am saving some emp information (Name,city,etc)
Now i want to hold form values with Node, so that if i double click on same node it should show same values again with form.
How to save values with Node?


Thanks
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #1 - Aug 8th, 2011 at 1:24pm
Print Post  
You can use the Tag property of the items to associate any custom information with them. Alternatively you can derive from ShapeNode and implement any custom properties on the derived class. Another option would be to use attached properties.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #2 - Aug 8th, 2011 at 1:27pm
Print Post  
If you also want to serialize/deserialize your custom data when the diagram containing the node is saved/loaded, deriving from ShapeNode might be the best solution. Then you can override the SaveToXml and LoadFromXml methods to save/load your custom properties.

Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #3 - Aug 8th, 2011 at 1:28pm
Print Post  
Hi
Thanks for reply,
Can you tell me code example that how to create custom properties on the derived class for ShapeNode?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #4 - Aug 8th, 2011 at 1:56pm
Print Post  
Take a look at Tutorial #3 - it illustrates how to derive from ShapeNode. The derived class is called OrgChartNode and implements two custom properties - Title and FullName.

I hope this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #5 - Aug 9th, 2011 at 4:36am
Print Post  
Thanks ,
I have Created one derived class ChartNode

Code
Select All
 public class ChartNode : ShapeNode
    {
	  public ChartNode()
		{
		DefaultStyleKey = typeof(ChartNode);
		}

	  public int FormID
		{
		get { return (int)GetValue(FormIDProperty); }
		set { SetValue(FormIDProperty, value); }
		}

	  public static readonly DependencyProperty FormIDProperty = DependencyProperty.Register(
		"FormID",
			typeof(int),
		typeof(ChartNode),
			new PropertyMetadata(""));

	  public int FormDecisionGroupID
		{
		get { return (int)GetValue(FormDecisionGroupIDProperty); }
		set { SetValue(FormDecisionGroupIDProperty, value); }
		}

	  public static readonly DependencyProperty FormDecisionGroupIDProperty = DependencyProperty.Register(
		"FormDecisionGroupID",
			typeof(int),
		typeof(ChartNode),
			new PropertyMetadata(""));
    }
 



And I am using it like this

Code
Select All
 foreach (string shapeId in Shape.Shapes.Keys)
		{
	    ChartNode node = new ChartNode();
 node =(ChartNode)diagram.Factory.CreateShapeNode(x, y, 50, 50);
    node.Shape = Shape.Shape[shapeId];
			  x += size + 4;
			  if (x > (shapesPerRow - 1) * (size + 5))
			  {
				y += size + 4;
				x = 0;
			  }
			  node.Text = shapeId;
			  node.TextWidth = 200;
			  node.Locked = true;
		    }
 



But at line
ChartNode node = new ChartNode();
its throwing error : The type initializer for 'ChartNode' threw an exception.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #6 - Aug 9th, 2011 at 6:23am
Print Post  
You are supplying string default values ("") to dependency properties of type int. Change the following lines in your code:

Code
Select All
new PropertyMetadata("") 


to:

Code
Select All
new PropertyMetadata(0) 


Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #7 - Aug 9th, 2011 at 8:30am
Print Post  
Hi,
Above error is solved but now
at Line
node =(ChartNode)diagram.Factory.CreateShapeNode(x, y, 50, 50);

Unable to cast object of type 'MindFusion.Diagramming.Silverlight.ShapeNode' to type 'ChartNode'.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #8 - Aug 9th, 2011 at 9:30am
Print Post  
The CreateShapeNode method can only be used to create ShapeNode objects. Diagram nodes of custom types need to be instantiated explicitly and then added to the Diagram.Nodes collection.

Code
Select All
var node = new ChartNode();
node.Bounds = new Rect(x, y, 50, 50);
diagram.Nodes.Add(node); 


I hope this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #9 - Aug 9th, 2011 at 11:45am
Print Post  
Hi
As you can see, I am adding all types of shapes into diagram for drag n drop logic

Code
Select All
foreach (string shapeId in Shape.Shapes.Keys)
{
 ChartNode node = new ChartNode();
 node =(ChartNode)diagram.Factory.CreateShapeNode(x, y, 50, 50);
 node.Shape = Shape.Shape[shapeId];  x += size + 4;
if (x > (shapesPerRow - 1) * (size + 5))
  {

y += size + 4;

x = 0;
  }
  node.Text = shapeId;
  node.TextWidth = 200;
  node.Locked = true;
  }
 



Please suggest me changes for this code only bcz code which you mention above is not working for me
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #10 - Aug 9th, 2011 at 11:53am
Print Post  
Try this:

Code
Select All
foreach (string shapeId in Shape.Shapes.Keys)
{
      ChartNode node = new ChartNode();
      node.Bounds = new Rect(x, y, 50, 50);
      diagram.Nodes.Add(node);
      node.Shape = Shape.Shapes[shapeId];  x += size + 4;
      if (x > (shapesPerRow - 1) * (size + 5))
      {
            y += size + 4;
            x = 0;
      }
      node.Text = shapeId;
      node.TextWidth = 200;
      node.Locked = true;
} 


Please, note that we are not calling CreateShapeNode, instead we are adding the node directly to the Diagram.Nodes collection.

I hope this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #11 - Aug 9th, 2011 at 12:17pm
Print Post  
ok,
i have done the changes, but now shapes are not visible in diagram. ??? I debug the code , all shapes are added but not visible in diagram.

below is the sample where i am doing changes :
https://mindfusion.eu/_samples/_sample_DragDrop3.zip


  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Need to hold values with node
Reply #12 - Aug 9th, 2011 at 1:05pm
Print Post  
If you haven't defined a custom template for your node, remove or comment the following line:

Code
Select All
DefaultStyleKey = typeof(ChartNode); 


Regards,
Meppy
  
Back to top
 
IP Logged
 
SL_developer
YaBB Newbies
*
Offline


coding rocks

Posts: 43
Joined: Jul 26th, 2011
Re: Need to hold values with node
Reply #13 - Aug 10th, 2011 at 4:44am
Print Post  
thanks .. it works   Grin
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint