Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Changing bounds doesn't raise sizechange event (Read 6029 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Changing bounds doesn't raise sizechange event
Apr 1st, 2010 at 11:58am
Print Post  
Hi Stoyo

If I change the bounds of diagram node the SizeChanged event stops firing for the nodes.

I have following xaml code
Code
Select All
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Height="Auto" Width="Auto" >
<diag:Diagram Name="diagram" Bounds="0,0,300,300" HorizontalAlignment="Center" VerticalAlignment="Center" BackBrush="Beige">
</diag:Diagram>
</ScrollViewer>
 



And in code behind following code is available
Code
Select All
void diagram_NodeModified(object sender, NodeEventArgs e)
{
double left, top, width, height;
if ((Math.Min(diagram.Bounds.Left, e.Node.Bounds.Left) < diagram.Bounds.Left))
{
left = e.Node.Bounds.Left;
top = diagram.Bounds.Top;
width = diagram.Bounds.Width + (Math.Abs(diagram.Bounds.Left - e.Node.Bounds.Left)) * 2;
height = diagram.Bounds.Height;
diagram.Bounds = new Rect(left, top, width, height);
}
if (Math.Min(diagram.Bounds.Top, e.Node.Bounds.Top) < diagram.Bounds.Top)
{
left = diagram.Bounds.Left;
top = e.Node.Bounds.Top;
width = diagram.Bounds.Width;
height = diagram.Bounds.Height + (Math.Abs(diagram.Bounds.Top - e.Node.Bounds.Top)) * 2;
diagram.Bounds = new Rect(left, top, width, height);
}
if (Math.Max(diagram.Bounds.Right, e.Node.Bounds.Right) > diagram.Bounds.Right)
{
left = diagram.Bounds.Left - (e.Node.Bounds.Right - diagram.Bounds.Right);
top = diagram.Bounds.Top;
width = diagram.Bounds.Width + (e.Node.Bounds.Right - diagram.Bounds.Right) * 2;
height = diagram.Bounds.Height;
diagram.Bounds = new Rect(left, top, width, height);
}
if (Math.Max(diagram.Bounds.Bottom, e.Node.Bounds.Bottom) > diagram.Bounds.Bottom)
{
left = diagram.Bounds.Left;
top = diagram.Bounds.Top - (e.Node.Bounds.Bottom - diagram.Bounds.Bottom);
width = diagram.Bounds.Right - diagram.Bounds.Left;
height = diagram.Bounds.Height + (e.Node.Bounds.Bottom - diagram.Bounds.Bottom) * 2;// -this.Bounds.Top;
diagram.Bounds = new Rect(left, top, width, height);
}
}
 



The node modifed event changes the bounds of diagram control.
In my sample, I placed the diagram control centrally. By default it has some width & height.
Any node which i create in the default available place and attach a size_changed event for same starts firing the event for that whenever size is changed.

Now positing the node outside the bounded region, the amount of node moved left , I add same amount of space * 2 to the right side to show my node to same position where mouse is released.

Once bounds are changed, my size_changed event stops firing.

How i resolve this situation.

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing bounds doesn't raise sizechange event
Reply #1 - Apr 2nd, 2010 at 9:28am
Print Post  
Hi Rajesh,

We don't have any control over SizeChanged. It's something that the Silverlight layout system raises during the layout pass. Can't you use NodeModified instead of SizeChanged?

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Changing bounds doesn't raise sizechange event
Reply #2 - Apr 2nd, 2010 at 12:18pm
Print Post  
Hi Stoyo

The issue is that when the node sizechanged event is not fired, I would be able to see the anchor points at expected position but the color doesn't get applied fully for my node.

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing bounds doesn't raise sizechange event
Reply #3 - Apr 7th, 2010 at 1:50pm
Print Post  
Hi Rajesh,

We have managed to reproduce this when the alignment grid is shown. Does you application display the grid?

The node modification code forces the arrange pass of the Silverlight layout system (which is asynchronous otherwise) in order to update the nodes position immediately while drawing with the mouse. However it seems setting the panel's size just after the arrange pass is triggered somehow breaks the layout system and next arrange passes do not run as expected. We'll check if raising NodeModified before the node calls UpdateLayout will help - in such case the panel's size will be updated before the layout.

We have also noticed that drawing a new node fixes this, and so tried adding a temporary visual after setting Bounds as a workaround.

diagram.Bounds = ...;
var temp = new TextBlock();
diagram.DocumentPlane.Children.Add(temp);
diagram.DocumentPlane.Children.Remove(temp);

This seems to help, though we could still reproduce this by starting a new modification very quickly after Bounds is changed.

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Changing bounds doesn't raise sizechange event
Reply #4 - Apr 8th, 2010 at 7:29am
Print Post  
Hi Stoyo

Its nice that you are able to reproduce it and hope you will have a correct fix for same as soon as possible.

For your information, I am not displaying grid. And whenever I resize any node, "NodeModified" event which is on diagram control gets raised always.

Also, I have subclassed the the Diagram class and using it.

-Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing bounds doesn't raise sizechange event
Reply #5 - Apr 8th, 2010 at 9:00am
Print Post  
Yes, NodeModified is immediately raised by the control in response to MouseMove, while SizeChanged is raised by the Silverlight layout system asynchronously at some point in time...

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Changing bounds doesn't raise sizechange event
Reply #6 - Apr 12th, 2010 at 3:08pm
Print Post  
Hi Stoyo

Any updates on this issue ? Are you able to get the correct fix for same.

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing bounds doesn't raise sizechange event
Reply #7 - Apr 12th, 2010 at 3:53pm
Print Post  
Not yet.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing bounds doesn't raise sizechange event
Reply #8 - May 6th, 2010 at 10:58am
Print Post  
Hi Rajesh,

We could not find any way to get the layout system consistently back in sync once the SizeChanged event stops raising. However it seems we've managed to stop this problem from happening by changing a bit the diagram's visual tree structure. In this version the diagram is now implemented as a Canvas inside ContentControl, and previously it was a Canvas inside a Border:
https://mindfusion.eu/_beta/diaglite_layoutsync.zip

Please check if this fixes the problem for you. Now we'll have to test if the change from border to canvas doesn't break something else, and will release this with a small update in a couple of weeks.

Also check the new AutoResize property of the diagram - it is enabled by default and you don't need to set Bounds in response to NodeModified anymore.

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