在 WPF 中使用 XAML Island 的 MapControl:默认地图层显示在自定义图块层之上

MapControl using XAML Island in WPF: default map layer is shown over custom tile layer

我使用 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 添加了一个 MapControl。我想完全删除默认地图,但它不起作用。

我已经在 UWP 应用程序中测试了原始 MapControl,它可以正常工作。

我在 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);
        }
    }

这是 WPF 应用程序。它在顶部显示 OpenStreetMap 层和默认的 Bing 地图层:

这是 UWP 应用程序,只能 OpenStreetMap 完美显示:

有什么解决方案可以在 WPF 中修复它吗?

更新

我发现这条线没有正确应用并导致了错误:

mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;

我终于找到了解决办法。将这些行添加到初始化代码中:

Windows.UI.Xaml.Controls.Maps.MapControl originalMapControl =
    mapControl.GetUwpInternalObject() as Windows.UI.Xaml.Controls.Maps.MapControl;

if (originalMapControl != null)
{
    originalMapControl.Style = MapStyle.None;
}

它修复了缺陷。