Page Index Toggle Pages: 1 [2] 3 4 5 Send TopicPrint
Very Hot Topic (More than 25 Replies) Operations in the diagram (Read 31455 times)
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #15 - Mar 19th, 2020 at 1:40pm
Print Post  
The following can do it:

Code
Select All
<Grid MouseDown="Grid_MouseDown" MouseUp="Grid_MouseUp">
  <diag:Ruler x:Name="ruler">
    <diag:Diagram x:Name="diagram" />
  </diag:Ruler>
  <Rectangle x:Name="vLine" HorizontalAlignment="Center" VerticalAlignment="Stretch" Width="0.5" Height="Auto" Stroke="Red" Margin="18" />
  <Rectangle x:Name="hLine" HorizontalAlignment="Stretch" VerticalAlignment="Center" Width="Auto" Height="0.5" Stroke="Red" Margin="18" />
</Grid> 



Code
Select All
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
    vLine.Visibility = hLine.Visibility = Visibility.Collapsed;
}

private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
{
     vLine.Visibility = hLine.Visibility = Visibility.Visible;
} 



For zoom, attach the following handler to the Diagram.MouseWheel event:
Code
Select All
private void OnDiagramMouseWheel(object sender, MouseWheelEventArgs e)
{
    if (e.Delta < 0)
        diagram.ZoomFactor = Math.Max(10, diagram.ZoomFactor - 15);
    else
        diagram.ZoomFactor = Math.Min(500, diagram.ZoomFactor + 15);
} 



Regards,
Lyubo,
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #16 - Mar 20th, 2020 at 1:58am
Print Post  
Thanks Smiley
How to control the position and size of Image on imageNode? Is there any sample code?
  

3_20_2.png (Attachment deleted)
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #17 - Mar 20th, 2020 at 2:06am
Print Post  
What WPF controls are included in the blue area in the picture? I want to use the diagram for interactive data use. Smiley
  

3_20_4.png (Attachment deleted)
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #18 - Mar 20th, 2020 at 7:44am
Print Post  
D wrote on Mar 20th, 2020 at 1:58am:
Thanks Smiley
How to control the position and size of Image on imageNode? Is there any sample code?


You can control the position of the image within the node via the ImageAlign and ImagePadding properties of the ShapeNode class. If you need to display an Image outside of the node, you can achieve that with a transparent attached node.

D wrote on Mar 20th, 2020 at 2:06am:
What WPF controls are included in the blue area in the picture? I want to use the diagram for interactive data use. Smiley


These controls aren't part of any MindFusion package. The left looks like a TreeView control with filtering options added. Probably can achieve something similar with the default WPF TreeView control with template changes. The bottom right control looks like a color picker and the bottommost one looks like a panel with widgets and buttons on it.

Regards,
Lyubo,
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #19 - Mar 20th, 2020 at 10:08am
Print Post  
Thanks a lot Smiley
I want to use the TextBox control to control the properties of ImageAlign and ImagePadding to control the position of the image displayed on the ShapeNode. How can I achieve this? Please give me a sample code.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #20 - Mar 20th, 2020 at 1:47pm
Print Post  
Hi,

The ImageAlign property's type is an enumeration, so maybe TextBox is not the best control to use. You can try with a ComboBox:

Code
Select All
myComboBox.ItemsSource = Enum.GetValues(typeof(ImageAlign)).Cast<ImageAlign>();
myComboBox.SelectionChanged += (sender, args) =>
{
	var node = diagram.ActiveItem as ShapeNode;
	if (node == null || node.Image == null)
		return;

	node.ImageAlign = (ImageAlign)myComboBox.SelectedItem;
}; 



For ImagePadding you can use a value converter eventually and the conversion will be similar to the below case handled from a button click event. Note that this code has no validation of the input. It will accept input in the form of "0,0,0,0":
Code
Select All
myButton.Click += (sender, args) =>
{
	var node = diagram.ActiveItem as ShapeNode;
	if (node == null || node.Image == null)
		return;


	string[] thicknessValues = myTextBox.Text.Split(',');

	node.ImagePadding = new Thickness(double.Parse(thicknessValues[0]),
		double.Parse(thicknessValues[1]),
		double.Parse(thicknessValues[2]),
		double.Parse(thicknessValues[3]));
}; 



Regards,
Lyubo,
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #21 - Mar 20th, 2020 at 2:58pm
Print Post  
Thanks a lot Smiley
Can the position of the image on the ShapeNode be determined by the coordinates of the ruler?
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #22 - Mar 23rd, 2020 at 3:08am
Print Post  
I want to change the mouse wheel to the center point in the view during the zoom in and zoom out events of the diagram instead of the current coordinate position of the mouse as the base point.
How to achieve? Is there any sample code? Smiley
« Last Edit: Mar 23rd, 2020 at 5:35am by D »  

3_23.png (Attachment deleted)
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #23 - Mar 23rd, 2020 at 3:37am
Print Post  
SmileyWhy is the drag of ShapeNode on the diagram restricted after removing the thumbnail part (the code part in the red area)?
  

3_23_1.png (Attachment deleted)
3_23_2.png (Attachment deleted)
3_23_3.png (Attachment deleted)
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #24 - Mar 23rd, 2020 at 3:38am
Print Post  
Added:Why is the drag of ShapeNode on the diagram restricted after removing the thumbnail part (the code part in the red area)? Smiley
  

3_23_4.png (Attachment deleted)
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #25 - Mar 23rd, 2020 at 4:07am
Print Post  
After the size of the ShapeNode is changed by the value of the TextBox, the size of the image in the ShapeNode should not be changed accordingly, and it should be kept at the original size. How to achieve this? Is there any sample code? Smiley
« Last Edit: Mar 23rd, 2020 at 5:37am by D »  

3_23_5.png (Attachment deleted)
3_23_6.png (Attachment deleted)
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #26 - Mar 23rd, 2020 at 4:17am
Print Post  
After double-clicking on any point in the ShapeNode, this point will coincide with the center point of the centerline, thereby moving the entire ShapeNode. How to achieve this? Is there any sample code? Smiley
« Last Edit: Mar 23rd, 2020 at 5:38am by D »  

3_23_7.png (Attachment deleted)
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Operations in the diagram
Reply #27 - Mar 23rd, 2020 at 7:13am
Print Post  
Please create new forum threads for new questions.

Quote:
Why is the drag of ShapeNode on the diagram restricted after removing the thumbnail part (the code part in the red area)?


The overview control only lets you scroll the diagram view, it has nothing to do with dragging nodes. If you want to enable scroll-by-drag in the diagram, set diagram.Behavior = Pan. If you need to move nodes within the diagram area, you should be able to do that by first clicking to select the node, and then dragging its selection handles. Setting diagram.ModificationStart = AutoHandles will let you drag nodes without selecting first.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #28 - Mar 23rd, 2020 at 7:16am
Print Post  
Hi,

D wrote on Mar 23rd, 2020 at 3:08am:
I want to change the mouse wheel to the center point in the view during the zoom in and zoom out events of the diagram instead of the current coordinate position of the mouse as the base point.
How to achieve? Is there any sample code? Smiley


Change the mouse wheel handler to this:
Code
Select All
		private void OnDiagramMouseWheel(object sender, MouseWheelEventArgs e)
		{
			var zoomRect = diagram.Viewport;
			if (e.Delta < 0)
				zoomRect.Inflate(10, 10);
			else
				zoomRect.Inflate(-10, -10);
			diagram.ZoomToRect(zoomRect, true);
		} 



D wrote on Mar 23rd, 2020 at 4:07am:
After the size of the ShapeNode is changed by the value of the TextBox, the size of the image in the ShapeNode should not be changed accordingly, and it should be kept at the original size. How to achieve this? Is there any sample code? Smiley


You can either change the size of the original image and use the ImageAlign.Center option (or another alignment depending on your requirements), or use the ImageAlign.Fit option while adjusting the ImagePadding value to correct for the new node size. For example, if your image needs to be 20,20px and your node's size is 40,40px - you'll set an ImagePadding value of 10. If the node's size is increased to 50,50px, padding will be increased to 15, etc.

D wrote on Mar 23rd, 2020 at 4:17am:
After double-clicking on any point in the ShapeNode, this point will coincide with the center point of the centerline, thereby moving the entire ShapeNode. How to achieve this? Is there any sample code? Smiley


Use the following code:
Code
Select All
diagram.NodeDoubleClicked += (sender, args) =>
{
	var node = args.Node;

	var posX = args.MousePosition.X - node.GetCenter().X;
	var posY = args.MousePosition.Y - node.GetCenter().Y;

	var newPos = new Point(
		diagram.Viewport.X + diagram.Viewport.Width / 2 - node.Bounds.Width / 2 - posX,
		diagram.Viewport.Y + diagram.Viewport.Height / 2 - node.Bounds.Height / 2 - posY);

	node.SetBounds(new Rect(newPos, node.Bounds.Size), true, true);
}; 



Regards,
Lyubo,
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #29 - Mar 23rd, 2020 at 8:46am
Print Post  
How can I achieve the effect in the picture. The starting position of the ShapeNode in the figure is on the right. How can I control the starting position of the ShapeNode to be left or right? Then control the size of the entire ShapeNode according to TextBox: Length and TextBox: Width, but it will not affect the size of the image. Does the figure use two ShapeNodes or just one ShapeNode and has special settings? What can I do to achieve the effect in the picture? Is there any sample code? Smiley
  

3_23_8.png (Attachment deleted)
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 3 4 5
Send TopicPrint