Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Overview of Node Types (Read 3498 times)
JRobere
YaBB Newbies
*
Offline


Watch This!

Posts: 8
Joined: May 19th, 2009
Overview of Node Types
Jun 15th, 2009 at 12:50pm
Print Post  
Hi Stoyo,

I'm loving this product but I'm a little confused as to which type of Node we should use in our application (Shape Node, Control Node, Container Node).

Is there a place you can direct me to that discusses the pros and cons and typical uses of each in one place with some sample code of how to properly use each of them?

Our Nodes will have lots of data behind them and I think we'll need more than a Shape Node because I want to show indicators of as many different properties as I can.  Like cell phone reception style bars on the right, cell phone battery life style bars on top, another little icon the lower left and info with different fonts in the center, etc.

I understand that doing this requires that we handle Deserialization on our own and that's acceptable but is it optimal to use Control Node and create a SL User Control or to use a Container Node and build the template?

Thanks for your help,

JR
  

JR
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview of Node Types
Reply #1 - Jun 15th, 2009 at 1:23pm
Print Post  
Hi JR,

I would use ControlNodes for anything that needs more complex appearance than a simple flowchart / block diagram. This will also let you use Silverlight templates and styles to build your nodes, run animations, and implement more elaborate event handling than simple clicks on the nodes.

A ControlNode hosting a user control should not be slower to render than a ShapeNode: since Silverlight does not provide lower-level graphics primitives, each ShapeNode is implemented as a composition of a Grid, TextBlock, Image and one or more Path controls

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
JRobere
YaBB Newbies
*
Offline


Watch This!

Posts: 8
Joined: May 19th, 2009
Re: Overview of Node Types
Reply #2 - Jun 15th, 2009 at 1:29pm
Print Post  
It helps a lot to get your confirmation Stoyo, thanks.

So is there some documentation you can point me to that demonstrates practical use of Control Nodes including Serialization/Deserialization?

Thanks,

JR
  

JR
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview of Node Types
Reply #3 - Jun 15th, 2009 at 1:54pm
Print Post  
Hi JR,

ControlNodes add just one property (Control) to what they derive from DiagramNode, so there isn't much documentation specific to them.

The Demo example uses ControlNodes in the Network diagram step, and you can find some sample deserialization code there. I've also found some serialization code in our test application:

Code
Select All
private void diagram_SerializeControl(object sender, ControlNodeEventArgs e)
{
	e.Handled = true;

	if (e.Node is ControlNode)
	{
		ControlNode ctNd = e.Node as ControlNode;
		if (ctNd.Control is TextBox)
		{
			TextBox tb = ctNd.Control as TextBox;
			e.Context.WriteString("TextBox", "ControlType", e.XmlElement);
			e.Context.WriteString(tb.Text, "Value", e.XmlElement);
		}
		else if (ctNd.Control is Button)
		{
			Button btn = ctNd.Control as Button;
			e.Context.WriteString("Button", "ControlType", e.XmlElement);
			e.Context.WriteString(btn.Content.ToString(), "Value", e.XmlElement);
		}
	}
}

private void diagram_DeserializeControl(object sender, ControlNodeEventArgs e)
{
	e.Handled = true;

	string str = e.Context.ReadString("ControlType", e.XmlElement);
	string value = e.Context.ReadString("Value", e.XmlElement);

	if ("TextBox".Equals(str))
	{
		TextBox tb = new TextBox();
		tb.Text = value;
		(e.Node as ControlNode).Control = tb;
	}
	else if ("Button".Equals(str))
	{
		Button btn = new Button();
		btn.Content = value;
		(e.Node as ControlNode).Control = btn;
	}
}
 



You can use the LINQ for XML API to save and load custom data, or use the helper e.Context methods as shown above.

If you are going to use only a few types of controls, you might create classes derived from ControlNode for each specific user control and override SaveToXml and LoadFromXml to serialize the custom data, rather than implementing the serialization code for all controls in a single event handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
JRobere
YaBB Newbies
*
Offline


Watch This!

Posts: 8
Joined: May 19th, 2009
Re: Overview of Node Types
Reply #4 - Jun 15th, 2009 at 2:00pm
Print Post  
Are you kidding? Of course that helps!

Thanks Stoyo,

JR
  

JR
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview of Node Types
Reply #5 - Jun 15th, 2009 at 2:04pm
Print Post  
8)
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint