Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to auto resize the AnchorPoint's size when the node's size is changing? (Read 3326 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to auto resize the AnchorPoint's size when the node's size is changing?
Nov 14th, 2014 at 8:48am
Print Post  
how to auto resize the AnchorPoint's size when the node's size is changing?
  

question.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to auto resize the AnchorPoint's size when the node's size is changing?
Reply #1 - Nov 14th, 2014 at 11:40am
Print Post  
Anchor points are always rendered with constant size at this time. If you use the ShowAnchors.Always option, you could set it to Never instead to hide the standard marks, and draw marks as part of nodes.

E.g. if that's a ShapeNode, add a decoration element to your custom shape definition at the position where you want to see anchor points. Then the decoration element will resize automatically when the node is resized. If that's a TemplatedNode, add an Ellipse to your Xaml template with appropriate sizing constraints.

Alternatively, you could pass MarkStyle.Custom to AnchorPoint constructor and draw the anchor point from DrawAnchorPoint event handler. You will also need to redraw anchor points when nodes are resized:

Code
Select All
private void OnDrawAnchorPoint(object sender, DrawAnchorPointEventArgs e)
{
	var point = e.AnchorPoint;
	var adorner = (AdornerVisual)VisualTreeHelper.GetParent(point);
	var node = (DiagramNode)Diagram.GetDiagramItem(adorner);
	var nodeSize = node.Bounds.Size;
	var radius = Math.Min(nodeSize.Width, nodeSize.Height);
	radius /= 8;

	var cx = point.RenderSize.Width / 2;
	var cy = point.RenderSize.Height / 2;
	e.Graphics.DrawEllipse(Brushes.White, new Pen(Brushes.Black, 1),
		new Point(cx, cy), radius, radius);
}

void RedrawAnchorPoints(DiagramNode node)
{
	var adorner = node.Adorner;
	var count = VisualTreeHelper.GetChildrenCount(adorner);
	for (int i = 0; i < count; i++)
	{
		var point = VisualTreeHelper.GetChild(adorner, i) as AnchorPoint;
		if (point != null)
			point.InvalidateVisual();
	}
}

private void OnNodeModified(object sender, NodeEventArgs e)
{
	RedrawAnchorPoints(e.Node);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to auto resize the AnchorPoint's size when the node's size is changing?
Reply #2 - Nov 15th, 2014 at 5:04am
Print Post  
Stoyo wrote on Nov 14th, 2014 at 11:40am:
Anchor points are always rendered with constant size at this time. If you use the ShowAnchors.Always option, you could set it to Never instead to hide the standard marks, and draw marks as part of nodes.

E.g. if that's a ShapeNode, add a decoration element to your custom shape definition at the position where you want to see anchor points. Then the decoration element will resize automatically when the node is resized. If that's a TemplatedNode, add an Ellipse to your Xaml template with appropriate sizing constraints.

Alternatively, you could pass MarkStyle.Custom to AnchorPoint constructor and draw the anchor point from DrawAnchorPoint event handler. You will also need to redraw anchor points when nodes are resized:

Code
Select All
private void OnDrawAnchorPoint(object sender, DrawAnchorPointEventArgs e)
{
	var point = e.AnchorPoint;
	var adorner = (AdornerVisual)VisualTreeHelper.GetParent(point);
	var node = (DiagramNode)Diagram.GetDiagramItem(adorner);
	var nodeSize = node.Bounds.Size;
	var radius = Math.Min(nodeSize.Width, nodeSize.Height);
	radius /= 8;

	var cx = point.RenderSize.Width / 2;
	var cy = point.RenderSize.Height / 2;
	e.Graphics.DrawEllipse(Brushes.White, new Pen(Brushes.Black, 1),
		new Point(cx, cy), radius, radius);
}

void RedrawAnchorPoints(DiagramNode node)
{
	var adorner = node.Adorner;
	var count = VisualTreeHelper.GetChildrenCount(adorner);
	for (int i = 0; i < count; i++)
	{
		var point = VisualTreeHelper.GetChild(adorner, i) as AnchorPoint;
		if (point != null)
			point.InvalidateVisual();
	}
}

private void OnNodeModified(object sender, NodeEventArgs e)
{
	RedrawAnchorPoints(e.Node);
} 



I hope that helps,
Stoyan


Thanks for you help,but I find it can't resolve my problem.now I attach my project to you.I wish you can give me more help. thanks!
  

EvSwitch.rar (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to auto resize the AnchorPoint's size when the node's size is changing?
Reply #3 - Nov 17th, 2014 at 8:51am
Print Post  
This project doesn't show how you are trying to resolve it. If you want to draw the anchor point marks, replace MarkStyle.Circle with MarkStyle.Custom when creating new AnchorPoint instances, copy the event handlers above to Window.xaml.cs and attach them to events in Xaml:

Code
Select All
NodeModified="OnNodeModified"
DrawAnchorPoint="OnDrawAnchorPoint" 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to auto resize the AnchorPoint's size when the node's size is changing?
Reply #4 - Nov 27th, 2014 at 7:12am
Print Post  
thanks, I know how to do it.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint