|Porting GDI+ to WPF|
These are the adventures I am having porting a GDI+ graphics intensive application to WPF
The work is rather maddening as so many things have changed, but the promises it holds must be worth a little struggle. The following, in no particular order are the aha moments after the banging of head.
|Spot the namespace|
|System.Windows||Point, Size. Both are now doubles, so PointF and SizeF, along with RectangleF etc, are gone.|
|System.Windows.Media.Imaging||BitmapImage - Bitmap is no more|
|System.Windows.Shapes||Line, Rectangle, Ellipse, Path|
The ImageList class is gone. Use
List<Image>instead, e.g. List<image> images = new List<image>();
SolidBrush has gone, replaced by SolidColorBrush. If you use named colours, you can do this:
SolidColorBrush brush = Brushes.Red;
GraphicsPath is no more, replaced by System.Windows.Shapes.Path. I used the GraphicsPath quite a lot, and its replacement is more confusing than a signpost pointing in the wrong direction.
Altogether, 3 new classes are required to draw a path. They are: PathFigure, PathGeometry and Path. You might be wondering why it takes 3 new classes to replace the old one. I sure am.
1. Create a Figure(), add LineSegment()s, ArcSegment()s etc.
2. Add the figure to the geometry with something like: geometry.Figures.Add(figure);
3. Add the geometry to the path, with something like: path.Data = geometry;
|Why you can't rotate a canvas by dragging with the mouse|
I have a mass of things drawn on a canvas, and rather than rotating each of them individually, I wanted to rotate the whole canvas at once. While I could have achieved this using a separate control, like a thumb as an adorner, or a slider of some kind, I wanted to click the canvas and drag it around.
The problem is that when the new RotateTransform is added to the canvas, or the angle of the existing transform is changed, the canvas is rotated. This rotation means the canvas has moved relative to the mouse, and a MouseMove() event is generated. The new coordinates are recalculated then fed to your MouseMove() handler, and another RotateTransform angle is calculated. This generates another MouseMove() and the whole thing repeats over and over again. The result is a decided judder.
I am now rotating each item individually. Hmmm. If you know how to do it, my email is above.