Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Databinding shapenode to ADO.NET dataset (Read 5058 times)
ana_tran
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Mar 12th, 2010
Databinding shapenode to ADO.NET dataset
Mar 13th, 2010 at 2:58am
Print Post  
I have created a WPF window application and added a diagramView to my MainWindow.xmal file.

       <ScrollViewer Grid.Column="0" Name="scrollViewer1" HorizontalAlignment="Left">
           <my:Diagram Name="diagram1"/>
       </ScrollViewer>


1. Is there anyway to bind my diagram to a dataset in XMAL, so that for each record return, draw a shapenode?

2. I also hoping to draw link connecting the shapenode based on relationship data return from the dataset.  Can this be done in XAML via databinding or do I have to use procedure code?

3. Lastly, I also like to change the background color of the shapenode based on the state returned from dataset.  Can this be achieved via databinding?

4. How do I make my diagramview scroll horizontal?


Lastly is more of design questions. 

1. Would you recommend putting my diagram inside diagramview?

2. should i place wpf control inside diagram view or should i place it outside?
<grid>
<stackpanel><diagram><stackpanel>
<stackpanel>
<button>...
<label>...
<gridview>...
<stackpanel>
<grid
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Databinding shapenode to ADO.NET dataset
Reply #1 - Mar 15th, 2010 at 1:43pm
Print Post  
1. Try adding a reference to MindFusion.Diagramming.Wpf.DataBinding.dll to your project and creating a DataBinder object:

Code
Select All
<d:Diagram x:Name="diagram" />

<d1:DataBinder x:Name="dataBinder"
	NodeClass="std:ShapeNode"
	NodeData="{StaticResource NodeDataSource}"
	LinkData="{StaticResource LinkDataSource}"
	NodeIdField="NodeId"
	LinkIdField="LinkId"
	LinkOriginIdField="OriginId"
	LinkDestionationIdField="DestinationId"
	DataBound="dataBinder_DataBound"
	NodeDataChanged="dataBinder_NodeDataChanged">
	<d1:DataBinder.Diagram>
		<Binding ElementName="diagram" />
	</d1:DataBinder.Diagram>

	<d1:DataBinder.NodeDataDictionary>
		<d1:BoundProperty Source="NewText" Destination="Text"></d1:BoundProperty>
		<d1:BoundProperty Source="Shape" Destination="Shape"></d1:BoundProperty>
		<d1:BoundProperty Source="NewBounds" Destination="Bounds"></d1:BoundProperty>
	</d1:DataBinder.NodeDataDictionary>

	<d1:DataBinder.LinkDataDictionary>
		<d1:BoundProperty Source="NewText" Destination="Text"></d1:BoundProperty>
	</d1:DataBinder.LinkDataDictionary>

</d1:DataBinder> 



This is kind of experimental and we have never released it officially. Also it supports only one-way binding.

2. It can be done if there is a second dataset that contains node IDs, as shown above.

3. You could do that in the dataBinder_DataBound handler, where you must also run some layout algorithm to arrange the nodes, e.g.

Code
Select All
private void dataBinder_DataBound(object sender, EventArgs e)
{
	MindFusion.Diagramming.Wpf.Layout.CircularLayout cl = new MindFusion.Diagramming.Wpf.Layout.CircularLayout();
	cl.Arrange(diagram);
} 



4. Set the ScrollViewer's HorizontalScrollbarVisibility.

1. You don't need that, unless you must show more views over the same diagram (MDI), which is not fashionable nowadays.

2. If you place controls inside the diagram, I think the diagram will treat them as nodes and create DiagramNodeAdapters.

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


I love YaBB 1G - SP1!

Posts: 5
Joined: Mar 12th, 2010
Re: Databinding shapenode to ADO.NET dataset
Reply #2 - Apr 16th, 2010 at 3:57am
Print Post  
Stoyan
I was trying your suggestiong but couldn't get it to work.  I don't see anything drawn.  When I was trying to step through the code, I seems like the DataItem for my diagram does contain the list of items, but for some reason nothing is being drawn.

           <ScrollViewer>
               <diag:Diagram Name="diagram1"
                             AllowDrop="True" SnapsToDevicePixels="True"
                             Height="416.625" Width="701.041" MeasureUnit="WpfPoint" MaxHeight="480" MaxWidth="720" Background="Bisque">

                   <db:DataBinder Name="dataBinder" DataContext="_componentList"
                                  NodeClass="std:ShapeNode"
                                  NodeData="{Binding}"
                                  NodeIdField="NodeId">
                       <db:DataBinder.Diagram>
                           <Binding ElementName="diagram1"/>
                       </db:DataBinder.Diagram>
                       <db:DataBinder.NodeDataDictionary>
                           <db:BoundProperty Source="NewText" Destination="Text"/>
                           <db:BoundProperty Source="Shape" Destination="Shape"/>
                           <db:BoundProperty Source="NewBounds" Destination="Bounds"/>
                       </db:DataBinder.NodeDataDictionary>
                                   
                       
                   </db:DataBinder>
               </diag:Diagram>
           </ScrollViewer>



In the code behind I did:
       public ObservableCollection<WpfUI.DataModel.Component> _componentList { get; set; }

       public TestWPFGraph(WpfUI.DataModel.Component component)
       {
           InitializeComponent();

           //this.DataContext = component;
           _componentList = new ObservableCollection<WpfUI.DataModel.Component>();
           _componentList.Add(component);
           this.DataContext = _componentList;
           this.diagram1.DataContext = _componentList;
       }

Any help would be appreciated.  Couldn't find any documentaiton on the DataBinder
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Databinding shapenode to ADO.NET dataset
Reply #3 - Apr 16th, 2010 at 3:42pm
Print Post  
Have you added a handler for the DataBound event? Does diagram.Nodes contain any nodes when it is raised? If it does contain nodes, try running some layout algorithm from the handler. The nodes might be added at 0,0 by default, and if diagram.Bounds starts at a different position, you might not be seeing them.

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


I love YaBB 1G - SP1!

Posts: 5
Joined: Mar 12th, 2010
Re: Databinding shapenode to ADO.NET dataset
Reply #4 - Apr 16th, 2010 at 4:19pm
Print Post  
Hi,
My diagram.Bounds=0,0,793.700787401575,1122.51968503937

The node bound is (0,0,75,75).  diagram.Nodes count=1.

I tried what you said below to add the circular layout to dataBinder_DataBound but still couldn't see anything.  Is there anything else I should do inside the dataBinder_DataBound.

Thanks
Anna
  
Back to top
 
IP Logged
 
ana_tran
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Mar 12th, 2010
Re: Databinding shapenode to ADO.NET dataset
Reply #5 - Apr 16th, 2010 at 4:28pm
Print Post  
I forgot to mention that my object which is an observable collection has 364 items in it.  The diagram.DataContext.count=364 items as well.

The diagram.Nodes.Count=1.  So the nodes were never created I guess.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Databinding shapenode to ADO.NET dataset
Reply #6 - Apr 16th, 2010 at 6:46pm
Print Post  
Hi,

I don't think you can set the binder's context to a code-behind variable like that. Try removing that assignment from the Xaml:

DataContext="_componentList"

You could probably set dataBinder.DataContext=_componentList from the code-behind, or directly assign _componentList to binding.NodeData.

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


I love YaBB 1G - SP1!

Posts: 5
Joined: Mar 12th, 2010
Re: Databinding shapenode to ADO.NET dataset
Reply #7 - Apr 22nd, 2010 at 3:33am
Print Post  
I tried setting the datacontext in the code behind
       public ObservableCollection<WpfUI.DataModel.Component> _componentList { get; set; }

       public TestWPFGraph(WpfUI.DataModel.Component component)
       {
           InitializeComponent();

           //this.DataContext = component;
           _componentList = new ObservableCollection<WpfUI.DataModel.Component>();
           //_componentList.Add(component);
           _componentList = new ObservableCollection <WpfUI.DataModel.Component> (component.SubComponent.ToList());
           this.DataContext = _componentList;
           this.dataBinder.DataContext = _componentList;

           this.diagram1.DataContext = _componentList;
       }

It's still not working.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Databinding shapenode to ADO.NET dataset
Reply #8 - Apr 23rd, 2010 at 8:37am
Print Post  
Here's a small example:
https://mindfusion.eu/_samples/BindingTest.zip

Setting DataContext is not enough, you must always set NodeData, and optionally LinkData. If setting them from the code-behind, you must also call the DataBind method. In addition, at this time the NodeIdField must be always set.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint