Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) form.Nodes.Count issue (Read 17620 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
form.Nodes.Count issue
Dec 21st, 2010 at 8:17am
Print Post  
Stoyo, im using form.Nodes.Count for enumearte nodes created, and i find this trouble.

Imagine you create 3 nodes, using form.Nodes.Count can easy automatic enumerate that nodes like

1
2
3


But i have a problem if i delete node 1 and create new node, that node no is enumarted like 1 or like 4 is enumerated like 3

I think this is correct due i have again 3 nodes on screen, but imagine i use form.Nodes.Count for show that information on node for enumearte the nodes, i have now 2 nodes enumerated like 3 when create new node.

I think this no is a bug, node.count act like that, counting nodes present on the form
But how can solve this situation and continue enumerating nodes when some node is deleted?
Some suggestion?
Bets regards!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #1 - Dec 21st, 2010 at 8:46am
Print Post  
If you need to assign consecutive ordinal numbers to nodes, you could use diagram.Tag as a counter - set it to 0 once a new diagram is created, and for each new node increment the counter and assign its value to the node.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #2 - Dec 22nd, 2010 at 5:10am
Print Post  
Stoyo, exist some clear example of how use diagram.Tag like you suggested ?
I cant find any example.
Best regards !
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #3 - Dec 22nd, 2010 at 10:40am
Print Post  
Try assigning the result from this method to each new node:

Code
Select All
int IncrementCounter()
{
	int counterValue = 0;
	if (diagram.Tag != null)
		counterValue = (int)diagram.Tag;
	diagram.Tag = ++counterValue;
	return counterValue;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #4 - Dec 22nd, 2010 at 5:34pm
Print Post  
Grin just pefect like all your suggestions !
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #5 - Dec 22nd, 2010 at 10:41pm
Print Post  
This work perfect, but nwo i cant fidn the way to make work when  copy nod eand then and paste.

I know copy paste is suposed be a exact copy, but i need paste node be enumerated correctly.

Some idea for do this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #6 - Dec 23rd, 2010 at 9:16am
Print Post  
You could set it from the NodePasted event handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #7 - Dec 23rd, 2010 at 9:37am
Print Post  
This is what im doing now:

    int IncrementCounter()
       {
           int counterValue = 0;
           if (form.Tag != null)
               counterValue = (int)form.Tag;
           form.Tag = ++counterValue;
           return counterValue;

       }


private void form_NodeCreated(object sender, MindFusion.Diagramming.Wpf.NodeEventArgs e)
       {


     

           if (form.DefaultControlType == typeof(MyButton))
           {
               MyButton Mbutton = (MyButton)e.Node.UIElement;

               Mbutton.Text = "Button " + IncrementCounter();                                  
           }
    

  private void form_NodePaste(object sender, MindFusion.Diagramming.Wpf.NodeEventArgs e)
       {
         //not understand what is the code : (
       }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #8 - Dec 23rd, 2010 at 9:53am
Print Post  
I suppose NodePasted should look like this:

Code
Select All
if (e.Node.UIElement is MyButton)
{
	MyButton Mbutton = (MyButton)e.Node.UIElement;
	Mbutton.Text = "Button " + IncrementCounter();
} 

  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #9 - Dec 23rd, 2010 at 10:17am
Print Post  
Sotyo, i already try that and not work.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #10 - Dec 23rd, 2010 at 11:11am
Print Post  
What did not work? Have you set this method as NodePasted handler in the Xaml file?
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #11 - Dec 23rd, 2010 at 6:55pm
Print Post  
Yes, check this:


<d:Diagram x:Name="form"

SelectAfterCreate="False"

AdapterHandlesStyle="HatchHandles"

GridSizeX="1"

GridSizeY="1"

NodeCreated="form_NodeCreated"

NodePasted="form_NodePaste"

NodeDeleted="form_NodeDeleted"

InitializeNode="form_InitializeNode"

NodeSelecting="form_NodeSelecting"







/>



int IncrementCounter()

{


int counterValue = 0;


if (form.Tag != null)


counterValue = (int)form.Tag;


form.Tag = ++counterValue;


return counterValue;

}




private void form_NodeCreated(object sender, MindFusion.Diagramming.Wpf.NodeEventArgs e)

{



if (e.Node.UIElement is MyButton)


{


MyButton Mbutton = (MyButton)e.Node.UIElement;


Mbutton.Text = "B " + IncrementCounter();








}


}






private void form_NodePaste(object sender, MindFusion.Diagramming.Wpf.NodeEventArgs e)

{


if (e.Node.UIElement is MyButton)


{


MyButton tbutton = (MyButton)e.Node.UIElement;


Mbutton.Text = "Button " + IncrementCounter();


}


}


  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #12 - Dec 23rd, 2010 at 6:57pm
Print Post  
Using this code, i create first button and is named Button 1

When copy and paste,   is called as Button 1   not like Button 2
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: form.Nodes.Count issue
Reply #13 - Dec 27th, 2010 at 3:44pm
Print Post  
Some idea why this not work?

Best regards.
« Last Edit: Dec 27th, 2010 at 10:56pm by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: form.Nodes.Count issue
Reply #14 - Dec 28th, 2010 at 11:58am
Print Post  
It seems it's the same problem as with events. XamlReader can load binding expressions from your original Xaml, but XamlWriter cannot write them. It writes only the local value of the child control's property instead of the binding, and when it's loaded the child control is no longer bound to the Text property in your user control. Now the DiagramNodeAdapter.Clone method called when copying to the clipboard uses XamlWriter and XamlReader internally but does not raise the SerializeControl event, so there's no easy workaround. We'll make the Clone code raise Serialize/Deserialize events for the next release in January.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint