UWP Mapcontrol - 绑定(bind)到不同 MapElement 的集合并将它们排列在层中

标签 uwp win-universal-app uwp-xaml uwp-maps

我在 UWP MapControl 上显示几种不同类型的 MapElement,并在用户使用 map 时定期更新它们的位置、大小等。目前我用代码完成所有这些工作。我想找到一种绑定(bind)多个不同 MapElements 集合的便捷方法,因为这样我需要维护的代码就会更少。

在 Creator 的秋季更新 16299 中,Microsoft 添加了 MapElementsLayer class,它似乎非常适合这项工作,但我无法让它工作。 当我将它绑定(bind)到 MapElement3D 的 ObservableCollection 时,我没有看到它们中的任何一个出现在 map 上。我究竟做错了什么?

<Maps:MapControl 
        x:Name="MainMap"           
        MapProjection="Globe"
        ZoomLevel="15.5"

        <Maps:MapElementsLayer x:Name="Cars"  MapElements="{x:Bind _VehicleCollection, Mode=OneWay}"  />

 </Maps:MapControl>

最佳答案

I'd like to find a convenient way of binding multiple different collections of MapElements, as then I'd have less code to maintain.

正如您所提到的, map 分层 API 可以帮助表示您可以将数据绑定(bind)到的 map 数据集合。与现有的 MapControl.MapElements API 不同,它可用于将元素组作为一个单元独立操作或指定联合用途。

但是您需要使用MapControl.Layers将数据收集绑定(bind)到 map 。这是使用 MapElements 集合无法做到的事情。更多关于 map 分层API及操作方法请引用Working with layers 。例如:

<Maps:MapControl
    x:Name="myMap"
    Layers="{x:Bind ViewModel.LandmarkLayer}"
    MapProjection="Globe"
    MapServiceToken="Your token" />

您需要将图层集合绑定(bind)到MapControl.Layers属性。

关于UWP Mapcontrol - 绑定(bind)到不同 MapElement 的集合并将它们排列在层中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47674804/

相关文章:

c# - 对齐分组 GridView 中的标题和项目

3d - UWP 在中渲染 3D 模型

c++ - 使用 fopen 在桌面上打开文件时权限被拒绝

c# - UWP 中的绑定(bind)未设置附加行为属性

c# - 我的 UWP 应用无法读取 txt 文件

c++ - 在现有 UWP 项目中对代码进行单元测试的预期方式?

c# - 从 UWP 应用程序请求永久访问文件夹

c# - 命令(ICommand)和点击事件的区别

xaml - 何时在 UserControl 上使用模板化控件?

c# - 将新设备添加到 xaml 布局设计器 Visual Studio 2015 UWP