With the universal maps control in the Windows 10 SDK preview, we see a major shift from the old Bing Maps control to this major MVVM friendly control that can be used with all the Windows platforms through the Universal App Platform (UAP) without any changes to code.
The MapControl is now part of the Windows.UI.Xaml.Controls namespace. If you’ve created a previous application that integrates with the old Bing Maps control, you’ll find the new implementation minimal as the changes are only slight.
To get yourself started with adding a map to your XAML page, it’s as easy as:
<maps:MapControl x:Name="myMap" HorizontalAlignment="Left" />
This core map control has bindings for ZoomLevel, Heading, DesiredPitch and many more. However, before you get frustrated that there is no Items or ItemsSource binding, this is because the MapControl requires a child element for binding items to it.
This is achieved as follows:
<maps:MapControl x:Name="myMap" HorizontalAlignment="Left"> <maps:MapItemsControl x:Name="MapItems" ItemsSource="{Binding}" /> </maps:MapControl>
The fun doesn’t end there though. As this is essentially a ListView, we have the ability to build up an ItemTemplate for the Map to render your items as.
<maps:MapControl x:Name="myMap" HorizontalAlignment="Left"> <maps:MapItemsControl x:Name="MapItems" ItemsSource="{Binding}"> <maps:MapItemsControl.ItemTemplate> <DataTemplate> <Button x:Name="MapItemButton" Background="Transparent"> <StackPanel> <Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <TextBlock Text="{Binding Title}"/> </Border> <Image Source="{Binding ImageSourceUri}" maps:MapControl.Location="{Binding Location}"> <Image.Transitions> <TransitionCollection> <EntranceThemeTransition/> </TransitionCollection> </Image.Transitions> </Image> </StackPanel> </Button> </DataTemplate> </maps:MapItemsControl.ItemTemplate> </maps:MapItemsControl> </maps:MapControl>
This makes it a lot easier for developers to create maps within their applications in an MVVM friendly way with the freedom to customise it as they wish.
There are some major improvements with the updates to the universal app model which will see more controls across WinRT being unified so that they can be used across multiple devices and multiple platforms.
References