I created a Bing Maps WPF dialog box and would like set the center and zoom level programmatically. I have tried using SetValue()
, but I haven't found the right property to pass to it.
Here is the XAML for my Bing Maps dialog:
<Window
x:Class="RAPMkI.BingMapsDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
Title="BingMapsDialog" Height="378" Width="467">
<Grid>
<m:Map CredentialsProvider="Haha, nice try."/>
<Button Content="Locate" Margin="0,0,0,0" Name="button1" HorizontalAlignment="Right" Width="Auto" Height="Auto" VerticalAlignment="Top" />
</Grid>
</Window>
The code-behind looks like this:
namespace RAPMkI
{
/// <summary>
/// Interaction logic for BingMapsDialog.xaml
/// </summary>
public partial class BingMapsDialog : Window
{
public BingMapsDialog(Location center, int zoom)
{
InitializeComponent();
}
}
}
Is there a way to set the center and zoom level of my dialog box upon initialization, using the Location
and zoom that I have passed it?
I realize this is an older question, but the answer accepted is not correct anymore, if it ever was, so I'm hoping this will help someone else.
Center
is property not a method so trying to set it won't work. I banged my head against the wall for a while on that too, and kept ending up off the West coast of Africa (Lat: 0, Long: 0).
What you're looking for is SetView(Location location, Double Zoom)
Here's the reference for that:
https://msdn.microsoft.com/en-us/library/hh709343.aspx
To rewrite the example above:
public BingMapsDialog(Location center, double zoom)
{
InitializeComponent();
theMap.SetView(center, zoom);
}
Should be all that's needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With