Windows Phone 7 - Bing Maps MVVM Pushpin initialization
Does anyone have a good guideline on how to initialize a pushpin on the Bing Maps control? My current scenario works, but is not 100% correct... let me explain the details:
When I open the page with the Bing Maps control on it, I want the user to be able to push a small button that will show his current location. To show the current location, I'm using a Pushpin. I'm already adding the Pushpin on the control in the XAML file like thi开发者_如何学Gos:
<map:Pushpin> x:Name="currentLocation" Location="{Binding CurrentLocation}" Content="Me" ManipulationStarted="CurrentLocationPin_ManipulationStarted" </map:Pushpin>
Now with this scenario there a some problems! One, the pushpin is always visible! So how do I go about this? ( I know I can bind the Visibility also to a property and use a bool to visibility converter, but is this the best way to do this? ) Secondly, now I don't initialize the Location in the viewmodel... but for semantic reasons I would love to initialize the default value to Geocoordinate.Unkown ( that way I can use this to do checks when the user tries to do some manipulation before a currentlocation is set ). But when I initialize the pushpin on startup I get following error: "UIElement.Arrange(finalRect) cannot be called with Infinite or NaN values in finalRect.". So my question again :) what is a good guideline to setting up a currentlocation pushpin? ( but do mind that the users has to push a small application bar button before the currentlocation is set )
The initialization problem is due to the visibility of the Pushpin
. If the initial visibility of the Pushpin
is Collapsed
, then it won't take part in the arrange pass, so you won't get the error.
If you're using a view model to back this view, then I don't see a problem with exposing a property from the view model that determines whether the Pushpin
should be visibile or not. Yes you could use a boolean to visibility converter, but you could save some processing by actually exposing a Visibility
property (which is the approach I've used).
If you're using a command to initiate showing the Pushpin
from the button push (the Silverlight Windows Phone Toolkit has a behavior to enable hooking up application bar buttons to commands).
精彩评论