The issue
I've got an application that tracks vehicles on a map. However I cannot get the little buggers to rotate in the direction of their motion. Basically, all of them are going sideways! Ugh!
The code
Image vehicleImage = new Image
{
//Set image size and source
};
RenderTransform rotation= new RotateTransform{Angle = X};
vehicleImage.RenderTransfrom = rotation;
_mainMap.Children.Add(vehicleImage);
MapControl.SetLocation(vehicleImage, _position);
The Image, placed on the map, seems to completely ignore any angle I try to apply.

To understand why the rotation doesn't take effect, let's first take a look at the image below, which is taken from the Live Visual Tree in Visual Studio -
I use a
Rectanglebut in your case, you will see yourImagecontrol there instead. When you insert it into theMapControl.Childrencollection, it will be wrapped with a special element calledMapOverlayPresenter(as shown in the picture).This
MapOverlayPresenteris an internal element withinMapControland surprisingly, there's no official documentation on the Internet on what exactly it does. My guess is, as you zoom or rotate the map, this overlay simply responds by zooming or rotating in the opposite direction in order to maintain the original size and rotation of the child element, and this is causing the rotation transform of your innerImageto somehow get lost.(P.S.
RotationAngleandRotationAngleInDegreesfrom Composition have no effect here either.)Solution
The way to work around this is simple - instead of exposing the rotation transform on the
Imagedirectly, create aUserControlcalledImageControlwhich encapsulates thisImageand its transform, with dependency properties likeUriPathandAnglethat are responsible for passing the information down to the innerImageand itsCompositeTransformproperty.The
ImageControlXAMLThe
ImageControlcode-behindHow to use this
ImageControlOutcome
Hope this helps!