Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to set DataContext for ShapeNode? (Read 2030 times)
venki5star
Junior Member
**
Offline



Posts: 82
Location: India
Joined: Mar 9th, 2010
How to set DataContext for ShapeNode?
Apr 20th, 2010 at 10:58am
Print Post  
Hi,
I have a shape node which is created using the following code,

diagram.Factory.CreateShapeNode(...

I wanted to set the DataContext for the created node, how to achieve this?

Please help. Its very urgent.
  

Castle Rider
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to set DataContext for ShapeNode?
Reply #1 - Apr 20th, 2010 at 12:46pm
Print Post  
Hi,

ShapeNode does not derive from FrameworkElement and does not have DataContext property. You'll have to use controls wrapped in DiagramNodeAdapters if you need to databind nodes.

Stoyan
  
Back to top
 
IP Logged
 
venki5star
Junior Member
**
Offline



Posts: 82
Location: India
Joined: Mar 9th, 2010
Re: How to set DataContext for ShapeNode?
Reply #2 - Apr 20th, 2010 at 2:12pm
Print Post  
Do you have any sample for this?
  

Castle Rider
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to set DataContext for ShapeNode?
Reply #3 - Apr 21st, 2010 at 10:26am
Print Post  
For example you can let users draw ListViews or other FrameworkElements as below:

Code
Select All
public partial class Window1 : Window
{
	public Window1()
	{
		InitializeComponent();
		diagram1.DefaultControlType = typeof(ListView);
		diagram1.Behavior = Behavior.DrawControls;
	}

	private void diagram1_InitializeNode(object sender, NodeEventArgs e)
	{
		var patients = new[] { new Patient("Jhon", 28), new Patient("Roy", 40) };
		var listView = e.Node.UIElement as ListView;
		listView.ItemsSource = patients;
	}
}

public class Patient
{
	public Patient(string n, int a)
	{
		Name = n;
		Age = a;
	}

	public override string ToString()
	{
		return Name + " : " + Age;
	}

	public String Name { get; set; }
	public int Age { get; set; }
} 



Apart from ItemsSource you can set DataContext, ControlTemplate, DataTemplate etc. for the hosted FrameworkElements.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
venki5star
Junior Member
**
Offline



Posts: 82
Location: India
Joined: Mar 9th, 2010
Re: How to set DataContext for ShapeNode?
Reply #4 - Apr 21st, 2010 at 2:40pm
Print Post  
Thanks Stoyan.
  

Castle Rider
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint