Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Image (Read 2529 times)
dolfandon
Junior Member
**
Offline



Posts: 51
Location: Northern Virginia
Joined: Mar 12th, 2009
Image
Apr 16th, 2009 at 6:04pm
Print Post  
There is a demo on the web site called ready diagram. Is there source code for this? I want to display an image and text like that and was wondering how it was done. Thanks.

BTW, I want to do this programmatically.  i.e. add the nodes and set the images in the code file and not the xaml file.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Image
Reply #1 - Apr 17th, 2009 at 9:18am
Print Post  
The source code for the online demo is available under the Samples\CSharp\FCDemo subfolder of the DiagramLite installation folder. These nodes are implemented as a custom control there, though you could use ordinary shape nodes as well, by setting ImageAlign to Top and TextFormat to new StringFormat(Center, Far). To create a diagram like this entirely from code, you would probably have to apply some layout algorithm. E.g. create the nodes at random positions, and call the Arrange method of AnnealLayout or SpringLayout, though the result won't be as pretty as if the graph was arranged manually.

Stoyan
  
Back to top
 
IP Logged
 
dolfandon
Junior Member
**
Offline



Posts: 51
Location: Northern Virginia
Joined: Mar 12th, 2009
Re: Image
Reply #2 - Apr 17th, 2009 at 5:51pm
Print Post  
OK, this is what I have and I get ... a cyan square. No Image.

           ShapeNode node = new ShapeNode(Map1);
           node.Bounds = new Rect(200, 200, 64, 64);
           node.Brush = Brushes.Cyan;
           BitmapImage myImage = new BitmapImage();
           string imagePath = "/start_task24.jpg";
           myImage.UriSource = new Uri( imagePath, UriKind.Relative );
           node.Image = myImage;
           node.ImageAlign = ImageAlign.TopCenter;
           StringFormat sf = new StringFormat {Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center};
           node.TextFormat = sf;
           node.Text = "Start Node";
           node.Image = new Image().Source;
           Map1.Nodes.Add(node);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Image
Reply #3 - Apr 18th, 2009 at 7:58am
Print Post  
I think this will look for the image inside the application's .xap file. Have you set the image file as a content of the .xap? You can see ways to load images from different types of locations here:
http://blogs.msdn.com/katriend/archive/2008/04/27/different-ways-for-loading-ima...

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



Posts: 51
Location: Northern Virginia
Joined: Mar 12th, 2009
Re: Image
Reply #4 - Apr 20th, 2009 at 4:07pm
Print Post  
OK, I finally figured this out. It doesn't matter how I reference the image (part of the app file or just directly off the disk) What mattered is that I did it all in one step. This is the only code that worked.

           node.Image = new BitmapImage(new Uri(startImagePath, UriKind.Relative));

If I created the BitmapImage outside the setting of the image property it did not work.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint