Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Button inside a Node (Read 4039 times)
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Button inside a Node
Oct 23rd, 2013 at 10:32am
Print Post  
Hi Stoyan,

I was wondering if it was possible to be able to have a 'button' inside a certain node, with which you can add the same node underneath it?

If so, could you give an example?

Thanks in Advance.

Greets,

Sander
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Button inside a Node
Reply #1 - Oct 23rd, 2013 at 10:59am
Print Post  
Hi,

You could draw some button-like graphics from a Draw override and in NodeClicked check if mouse position is within the button area:

Code
Select All
public override void Draw(DrawingContext graphics, RenderOptions options)
{
	...
	var buttonBrush = new VisualBrush(buttonPainter);
	graphics.DrawRectangle(buttonBrush, null, new Rect(0, 0, 40, 20));
}

Button buttonPainter = new Button { Content = "Add", Width = 40, Height = 20}; 



You could as well add a real button as a node, and attach it to the main node.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Button inside a Node
Reply #2 - Oct 23rd, 2013 at 11:35am
Print Post  
Hi there,

At the moment, i get some sort of  image representing a button, but there are 2 problems that arise with this solution. (1) For some reason the NodeShape gets drawed first, so the 'Button' is behind the actual node and cant be pressed by the user. (2) For testing purposes I've moved the button in a way that i can press it with the cursor. But i cant actually press it. I need to be able to press it with the cursor so it adds a node of the same type as the root node.

Thanks in advance.

Greets,

Sander
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Button inside a Node
Reply #3 - Oct 23rd, 2013 at 1:29pm
Print Post  
The sample above just draws a button somewhere inside a node, it does not detect clicks. It will be drawn in front or behind the node's shape depending on whether you first call the base drawing code. You can detect clicks from a NodeClicked event handler by checking if the rectangle where you draw the button contains the mouse position. Alternatively, you could add the actual button to diagram.Nodes, attach it to main node, and add a Click event handler to it.

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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Button inside a Node
Reply #4 - Oct 23rd, 2013 at 2:06pm
Print Post  
Could you give an example? Embarrassed
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Button inside a Node
Reply #5 - Oct 24th, 2013 at 8:14am
Print Post  
Here's an example adding a new node from UIElement.OnMouseLeftButtonUp override:

Code
Select All
public override void Draw(DrawingContext graphics, RenderOptions options)
{
	...
	var buttonBrush = new VisualBrush(buttonPainter);
	graphics.DrawRectangle(buttonBrush, null, new Rect(0, 0, 40, 20));
}

Button buttonPainter = new Button { Content = "Add", Width = 40, Height = 20};

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
	base.OnMouseLeftButtonUp(e);

	var buttonRect = new Rect();
	buttonRect.Width = 40;
	buttonRect.Height = 20;

	if (buttonRect.Contains(e.GetPosition(this)))
	{
		var bounds = Bounds;
		bounds.Y = bounds.Bottom;

		var newNode = (DiagramNode)Clone(false);
		newNode.Bounds = bounds;
		Parent.Nodes.Add(newNode);
	}
} 



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


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Button inside a Node
Reply #6 - Oct 24th, 2013 at 9:56am
Print Post  
Hi Stoyan,

Nice, it works, although not the most prettiest solution. Think i will make a new node class and make it a child of the current class and use the logic from this solution.

More chocolate for you!

Greets,

Sander
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint