I am working on a WP7 app using Location Services and Bing Maps. I would like the Bing Maps control to rotate to always have the current heading at the top. I understand this isn't possible with the Bing Maps Control, so I'm trying to use a Rotation Transform to rotate the entire control.
I'm using the LayoutTransformerOnWindowsPhone assembly found here:
When the page loads, the control gets rotated to the correct heading, but it doesn't keep rotating as the heading changes. Here's my code:
Xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:LayoutTransformer>
<toolkit:LayoutTransformer.LayoutTransform>
<RotateTransform x:Name="mapRotation" />
</toolkit:LayoutTransformer.LayoutTransform>
<my:Map Name="map1" Margin="0,0,0,0" CredentialsProvider="xyz"/>
</toolkit:LayoutTransformer>
</Grid>
cs:
if (Compass.IsSupported)
{
_compass = new Compass {TimeBetweenUpdates = TimeSpan.FromMilliseconds(500)};
_compass.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<CompassReading>>(compass_CurrentValueChanged);
_compass.Start();
}
void compass_ValueChanged(object sender, SensorReadingEventArgs<CompassReading> e)
{
Dispatcher.BeginInvoke(() => UpdateUI(e.SensorReading));
}
private void UpdateUI(CompassReading compassReading)
{
_currentHeading = compassReading.TrueHeading;
mapRotation.Angle = _currentHeading;
}
It sounds like you're running into the Silverlight limitation I discuss in the third bullet point here: http://blogs.msdn.com/b/delay/archive/2008/07/03/the-layout-system-lies-have-become-a-bit-more-elaborate-layouttransform-functionality-updated-and-enhanced-for-silverlight-2-beta-2.aspx
Unfortunately, they broke the workaround I discuss there: http://blogs.msdn.com/b/delay/archive/2008/09/29/maintaining-pretenses-with-the-layout-system-layouttransform-functionality-updated-for-silverlight-2.aspx
So I introduced the TransformUpdated method which you should be able to call after updating the RotateTransform for the effect you want.
Also, FYI that there's another way to simplify this somewhat (though it's not necessary in your case) which I discuss here: http://blogs.msdn.com/b/delay/archive/2009/04/09/a-bit-more-than-meets-the-eye-easily-animate-layouttransformer-with-animationmediator.aspx
I hope this is helpful! :)