Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Binding the Nodes property (Read 2530 times)
IainS
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 1
Joined: Aug 11th, 2010
Binding the Nodes property
Aug 11th, 2010 at 11:16am
Print Post  
Hi,

I'm looking at WpfDiagram and I'm trying to populate the Nodes on the diagram using databinding (e.g., I'd like to bind the Nodes property to an ObservableCollection of objects and when the collection changes, have the diagram update accordingly).

I haven't found a way to do this, and I can't see this done in any of the supplied samples.

Is it possible to achieve what I'm trying to do?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Binding the Nodes property
Reply #1 - Aug 11th, 2010 at 11:41am
Print Post  
Hi,

WpfDiagram does not support databinding yet.

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


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Binding the Nodes property
Reply #2 - Sep 2nd, 2010 at 8:40am
Print Post  
Hi Stoyan,

I have the following class (example):

[code]
class Task : ShapeNode, INotifyPropertyChanged
{
string _taskname;
public event PropertyChangedEventHandler PropertyChanged;

public Task()
{
}

public string TaskName
{
get { return _taskname; }
set
{
_taskname = value;
OnPropertyChanged("taskname");
}
}

protected void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
[/code]

[code]
XAML:
<TextBox Name="Name" Text="{Binding Source=Task, Path=TaskName, UpdateSourceTrigger=PropertyChanged}" />[/code]

The user has a textbox to enter/change the TaskName. If the user activates another Node, the textbox shall view the TaskName of the selected Node.

If Binding isn't supported, what could be a recommended solution?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Binding the Nodes property
Reply #3 - Sep 2nd, 2010 at 9:07am
Print Post  
Hi,

You could set the last activated Task as a DataContext for the TextBox (or a panel that contains it along with other bound elements). For example:

Code
Select All
<TextBox Name="nameBox" Text="{Binding Path=TaskName, UpdateSourceTrigger=PropertyChanged}" />

void diagram_NodeActivated(object sender, NodeEventArgs e)
{
	if (e.Node is Task)
		nameBox.DataContext = e.Node;
} 



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


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Binding the Nodes property
Reply #4 - Sep 2nd, 2010 at 10:02am
Print Post  
Hi Stoyan,

works fine, thank you for this hint.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint