Hi Stoyo
If I change the bounds of diagram node the SizeChanged event stops firing for the nodes.
I have following xaml code
<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
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