I've added a MapControl
using this instruction to my WPF application. I wanted to add custom map layer to it, so I've added a OpenStreetMap
tile layer using this instruction. I want to remove the default map at all, but it doesn't work.
I've tested the original MapControl
in a UWP app and it works.
My code in WPF:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
Title="MainWindow" Height="450" Width="800">
<Grid>
<controls:MapControl x:Name="mapControl" />
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
HttpMapTileDataSource dataSource = new HttpMapTileDataSource("http://c.tile.openstreetmap.org/{zoomlevel}/{x}/{y}.png");
MapTileSource tileSource = new MapTileSource(dataSource);
tileSource.Visible = true;
tileSource.Layer = MapTileLayer.BackgroundReplacement;
tileSource.IsFadingEnabled = false;
mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;
mapControl.TileSources.Add(tileSource);
}
}
This is the WPF application. It shows OpenStreetMap
layer and also default Bing
map layer on top:
This is the UWP app and shows only OpenStreetMap
perfectly:
Is there any solution to fix it in WPF?
Update
I find out that this line doesn't apply correctly and it caused the error:
mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;
Finally I found the solution. Add these lines to the initialization code:
It fixes the defect.