Hi, I've got some issue :/
I have created group of nodes, by creating ShapeNode and attache other Nodes to it and create rectangle, which is around the group. I wanna mention, that I want to modify nodes inside the group, so that's why their Lock property is set to false.
private void CreateGroupButton_Click(object sender, RoutedEventArgs e)
{
if (FlowChart.Selection.Nodes.Count > 1)
{
var groupNode = FlowChart.Factory.CreateShapeNode(0, 0, 1, 1);
groupNode.ZBottom(false);
groupNode.Transparent = true;
groupNode.HandlesStyle = HandlesStyle.MoveOnly;
CreateGroup(groupNode, FlowChart.Selection.Nodes);
foreach (DiagramNode node in groupNode.SubordinateGroup.AttachedNodes)
{
node.Locked = false;
}
groupNode.SubordinateGroup.AutoDeleteItems = true;
FlowChart.Selection.Change(groupNode);
}
}
private static void CreateGroup(DiagramNode node, DiagramNodeCollection children)
{
Rect r = Rect.Empty;
foreach (var child in children)
{
Rect cb = child.Bounds;
r = r.IsEmpty ? cb : Rect.Union(r, cb);
}
double margin = 5;
r.Inflate(margin, margin);
node.Bounds = r;
foreach (var child in children)
{
child.AttachTo(node, AttachToNode.TopLeft);
}
}
And my problem is, when I am modifying nodes inside the group. I'd like rectangle is adjusting to the position of the nodes. That's why I am creating rectangle every time node is modifying, but I don't know the node starts changing its size, when I only move it. Below it's the code:
private void FlowChart_NodeModifying(object sender, NodeValidationEventArgs e)
{
var nodes = FlowChart.Selection.Nodes;
var masterGroup = nodes.First().MasterGroup;
if (masterGroup != null)
{
var children2 = masterGroup.AttachedNodes.Cast<DiagramNode>();
var diagramCollection = new DiagramNodeCollection();
foreach (var diagramNode in children2)
{
diagramCollection.Add(diagramNode);
}
var masterNode = masterGroup.MainItem;
if (masterNode != null)
{
Regroup(masterNode as DiagramNode, diagramCollection);
}
}
}
private void Regroup(DiagramNode node, DiagramNodeCollection children)
{
Rect r = Rect.Empty;
foreach (var child in children)
{
Rect cb = child.Bounds;
if (r.IsEmpty)
{
r = cb;
}
else
{
r = Rect.Union(r, cb);
}
}
double margin = 5;
r.Inflate(margin, margin);
node.Bounds = r;
}
I wonder if you know, what issue it can be.
Thanks for your help.