Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Sample Code for TreeLayout Demo (Read 5566 times)
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
Sample Code for TreeLayout Demo
Jan 3rd, 2014 at 7:36am
Print Post  
Hi,

Can i get the sample code for the TreeLayout shown in one of those demos given by mindfusion(mindfusion.eu/demos/diagramlite)

Thanks in Advance.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Sample Code for TreeLayout Demo
Reply #1 - Jan 3rd, 2014 at 8:05am
Print Post  
Hi,

You should have that code installed together with other sample projects under C:\Program Files\MindFusion\Diagramming for...\VS20**\Samples folder. Here's the code anyway:

Code
Select All
public partial class Page : UserControl
{
    public Page()
    {
        InitializeComponent();
    }

    private void OnPageLoaded(object sender, RoutedEventArgs e)
    {
        diagram.DefaultShape = Shapes.Rectangle;
        diagram.LinkHeadShape = ArrowHeads.Triangle;

        rootNode = new ShapeNode(diagram);
        diagram.Nodes.Add(rootNode);

        rootNode.Image = image1.Source;
    }

    private void image_OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        draggedImage = sender as Image;
        CaptureMouse();
    }

    private void OnMouseMove(object sender, MouseEventArgs e)
    {
        if (draggedImage != null)
        {
            Point diagramPosition = e.GetPosition(diagram);
            DiagramNode parent = diagram.GetNodeAt(diagramPosition);
            if (parent != null)
                Cursor = Cursors.Eraser;
            else
                Cursor = Cursors.Hand;
        }
        else
        {
            Cursor = Cursors.Arrow;
        }
    }

    private void OnMouseUp(object sender, MouseButtonEventArgs e)
    {
        if (draggedImage != null)
        {
            ReleaseMouseCapture();

            Point diagramPosition = e.GetPosition(diagram);
            DiagramNode parent = diagram.GetNodeAt(diagramPosition);
            if (parent != null)
            {
                ShapeNode child = new ShapeNode(diagram);
                child.Image = draggedImage.Source;
                diagram.Nodes.Add(child);

                DiagramLink link = new DiagramLink(diagram, parent, child);
                diagram.Links.Add(link);

                var layout = new MindFusion.Diagramming.Layout.TreeLayout();
                layout.Arrange(diagram);
            }
        }

        draggedImage = null;
    }

    private ShapeNode rootNode;
    private Image draggedImage;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
Re: Sample Code for TreeLayout Demo
Reply #2 - Jan 3rd, 2014 at 9:43am
Print Post  
Thanks Stoyo, that was really helpful.

Now, I am able to do a tree layout in silverlight Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint