Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Converting from Windows Forms to WPF (Read 5733 times)
John Preston
YaBB Newbies
*
Offline


Lost Developer

Posts: 18
Joined: Mar 9th, 2011
Converting from Windows Forms to WPF
Mar 9th, 2011 at 6:50pm
Print Post  
We've moved our application from Windows Forms to WPF. Currently we are Windows Forms Hosting the Mindfusion Windows Forms components, but we'd like to move to native WPF and ideally Silverlight diagramming as well. Sadly, the developer that wrote all our code using these components isn't available now, so the first time I've seen all this is now, having been charged with converting them.

But I've been running into quite a few issues. A lot of the arrow heads, and shapes, and other things appear to be quite different. After a good amount of effort, I've converted over the code, and seem to have only have a few issues left. The amount of effort it's been to try and convert to WPF seems extreme, though, and I'm worried we're doing this wrong. Are there any guides about converting to the WPF components, and what changes need to be made?

1) The sizes as we have them saved on our diagrams from Windows Forms are apparently totally different in WPF, as we now have tiny little diagrams that are a fraction of the size they used to be. If I multiply all the sizes, and start positions and such by 4, it appears to be much closer in size to how it used to be. As close as I can get though, the distance between lanes seems to be calculated differently now.

2) We also used to attach images inside of nodes. No matter how I do this now, the image nodes don't seem to be visible. I've tried for testing to use other nodes, and other things, but AttachTo just doesn't seem to be working.

3) When we set lane titles, it seems to be defaulted to vertical text now, and if I set RotateTitle, the text just vanishes entirely rather than rotating to be horizontal as I expect.

4) Apparently, we've saved some links that point from a node to nowhere (or the same node) that didn't show up, and were ignored in the Windows Forms stuff, but now show up. Should we be handling these ourselves or is there an option to hide them?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Converting from Windows Forms to WPF
Reply #1 - Mar 9th, 2011 at 7:21pm
Print Post  
1) The Diagram.MeasureUnit property defaults to Millimeter in the WinForms version and WpfPoint in he WPF version. You can either set the WpfDiagram's MeasureUnit to Millimeter too, and set all length-related properties to the WinForms values, or multiply the millimeter values you were using in WinForms by 96/25.4 to get the correct WpfPoint lengths.

2) Are you attaching a Transparent node with an image to another node? If you see nothing then, check if the Image is different from null, or if the node size isn't too small for WpfPoints. Also consider using TemplatedNodes as in tutorials 3 and 4 instead of groups of nodes.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Converting from Windows Forms to WPF
Reply #2 - Mar 10th, 2011 at 7:03am
Print Post  
3) Could you post here your grid setup code? I've done some tests in the Lanes sample project but couldn't see any problems. The text appears horizontal by default and if I set longer headers they wrap to the second line:

grid.RowHeaders.Add(new Header("Task " + i + "test"));

4) Do you mean you are saving the diagram as xml file in the WinForms app, loading it in the WPF app, and it shows new unconnected links?
  
Back to top
 
IP Logged
 
John Preston
YaBB Newbies
*
Offline


Lost Developer

Posts: 18
Joined: Mar 9th, 2011
Re: Converting from Windows Forms to WPF
Reply #3 - Mar 11th, 2011 at 6:32pm
Print Post  
1) Now that explains a lot. I corrected that, but the font sizes seem unaffected. They are now very large, and drawn quite thickly. (I think most of what we use is Arial 10, and Microsoft Sans Serif 8.5)

The line thicknesses around all the nodes seems similarly thick.

2)These are definitely not transparent. I will look into templated nodes when I get a chance.

3) The code to add our lanegrids is quite complicated, long, and full of proprietary data types. The actual RowHeaders.Add part looks like this:

Code
Select All
dg.LaneGrid.RowHeaders.Add(New Lanes.Header("String")) 



4) No, we save... essentially sets of lanes, nodes, and links, and rebuild the diagram out of that information. In these cases, I'm fairly sure these... empty... links shouldn't have been added or saved. But we probably didn't know they were, until WPF when they start showing up.

I put comparison screenshots on an imagehost -

This is the diagram in Windows Forms:


This is it in WPF:

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Converting from Windows Forms to WPF
Reply #4 - Mar 14th, 2011 at 7:03am
Print Post  
1) The defaults for the size properties in the WPF version are suitable for the WpfPoint unit and changing Diagram.MeasureUnit does not automatically convert all other property values from the old unit to the new one. So if you set MeasureUnit to Millimeter, you must also set new values for font size, pen width, etc.

3) I think it will look better when you set a font size comparable to the first image.

4) Does that link have all of its points at the same position after you rebuild the diagram? Perhaps the WinForms control does not draw an arrowhead in such case, but WpfDiagram does.
  
Back to top
 
IP Logged
 
John Preston
YaBB Newbies
*
Offline


Lost Developer

Posts: 18
Joined: Mar 9th, 2011
Re: Converting from Windows Forms to WPF
Reply #5 - Mar 15th, 2011 at 6:27pm
Print Post  
Okay... I've solved my font size issues, the thickness issues, the links to nowhere, i even figured out why the little images on the nodes weren't showing up.

So I'm down to 2 issues.

One of which I think is my fault (lane heights).

However, my rectangular nodes appear to have a significant border radius in WPF, that were much smaller in Windows Forms. I can't seem to find a property to change that. Is there as a corner radius property I can access?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Converting from Windows Forms to WPF
Reply #6 - Mar 16th, 2011 at 7:21am
Print Post  
If you have decided to use the Millimeter unit, change the radius of the RoundRect shape:

diagram.MeasureUnit = GraphicsUnit.Millimeter;
Shapes.RoundRect.Outline = new[] {
     new RoundRectangleTemplate(0, 0, 100, 100, 3 /*radius in mm*/) };

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


Lost Developer

Posts: 18
Joined: Mar 9th, 2011
Re: Converting from Windows Forms to WPF
Reply #7 - Mar 16th, 2011 at 3:47pm
Print Post  
That did help. Thank you very much Stoyo.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint