Steps:
Create a new WPF project
Add a reference to the WPF Bing Maps Cotrol Beta DLL
Replace the MainWindow.xaml and MainWindow.xaml. vb witht eh code below
Press F5 to run
File: MainWindow.xaml
<window x:class="MainWindow" xmlns:x="#unknown">
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="MainWindow" Height="350" Width="525">
<grid>
<m:map x:name="MyMap" xmlns:m="#unknown" />
</grid>
</window>
File: MainWindow.xaml.vb
Class MainWindow
Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
' Build a ployline and add random coordinates to it every 2 seconds
Dim pl As New Microsoft.Maps.MapControl.WPF.MapPolyline()
pl.Stroke = New SolidColorBrush(Colors.Black)
pl.StrokeThickness = 5
pl.StrokeLineJoin = PenLineJoin.Round
pl.Locations = New Microsoft.Maps.MapControl.WPF.LocationCollection()
MyMap.Children.Add(pl)
Randomize()
Dim rnd As New Random()
Dim t As New Timers.Timer(2000)
AddHandler t.Elapsed, Sub()
Dispatcher.BeginInvoke(Sub()
' Add random point
pl.Locations.Add(New Microsoft.Maps.MapControl.WPF.Location(
rnd.Next(-180, 180), rnd.Next(-180, 180)))
' One workaround, Remove and re-add polyline, we wont use this anymore
'MyMap.Children.Remove(pl)
'MyMap.Children.Add(pl)
' better method, use JiggleMap
JiggleMap()
End Sub)
End Sub
t.Start()
End Sub
Private Sub JiggleMap()
' I find is best to run this in a background thread so as to avoid
' locking up the UI
Dim bw As New ComponentModel.BackgroundWorker()
AddHandler bw.DoWork, Sub(sender As Object, e As ComponentModel.DoWorkEventArgs)
' Retrieve current centre from arguments
Dim centre As Microsoft.Maps.MapControl.WPF.Location = e.Argument
' Create new centre which is only slightly differnet to current
Dim newcentre As New Microsoft.Maps.MapControl.WPF.Location(
centre.Latitude + 0.00000000001, centre.Longitude)
' Since we are in a BackgroundWorker we need to call back to the
' UI thread using the Dispatcher
Dispatcher.Invoke(Sub()
' Chage the map centre to the new centre
MyMap.Center = newcentre
End Sub)
' Setup a timer so we can reset the centre after a short break
' otherwise the change may not register before it is reset
Dim t As New Timers.Timer(125)
t.AutoReset = False
AddHandler t.Elapsed, Sub()
' Since we are in a BackgroundWorker we need to call back
' to the UI thread using the Dispatcher
Dispatcher.Invoke(Sub()
MyMap.Center = centre
End Sub)
End Sub
t.Start()
End Sub
' Pass in the current centre point of the map
bw.RunWorkerAsync(MyMap.Center)
End Sub
End Class