Bing Maps WPF Hack

Posted by Chris Gardner on Geeks with Blogs See other posts from Geeks with Blogs or by Chris Gardner
Published on Fri, 05 Oct 2012 11:50:28 GMT Indexed on 2012/10/09 15:40 UTC
Read the original article Hit count: 291

Filed under:

I've spent the past couple of days adding the Bing Maps WFP Control to an application I'm developing. I kept running into a strange thing that was driving me crazy. I have the control in the bottom of a StackPanel, under a Grid. No matter how hard I tried, setting the Height of the Bing control to Auto would cause the ActualHeight to always be 60.93.

Now, I still don't know why this is happening. Truth be told, I'm not too sure I care. I did, however, find a reasonable hack around the problem. I do know the size of everything else. As such, I tied into the SizeChanged Event of the StackPanel. Using this, I could set the Height to the correct size based on the new size of the panel.

private void ResizeMap( object sender, SizeChangedEventArgs e ) {
myMap.Height = ((StackPanel)sender).ActualHeight - 75.0;
}
The hard-coded number is was because I had a fixed height of controls above my map. If you have dynamic elements, you could easily iterate through them and delete out the portions.

So, there you have it. It's not much, but it annoyed the Smurf out of me for a brief period of time. Since I never found an answer, I figured I'd share.

© Geeks with Blogs or respective owner