MapItemsControl 不反映相应 ItemsSource 的删除

MapItemsControl does not reflect removing of corresponding ItemsSource

在 UWP-App (Windows 10) 中,我有一个 MapControl,我正在使用 MapItemsControl 为该地图提供叠加层。 MapItemsControlItemsSource(这是一个 ObservableCollection)通过 xaml 绑定,但只在一个方向上工作:

向该集合添加项目工作正常,这些项目也显示在 MapControl 中。 将项目删除到该集合也有效,但似乎只在该集合内 - 我的 MapControl 上的视觉表示不会对删除元素做出反应。这可能会导致向该地图无限添加项目,而不会删除任何项目。

ObservableCollection 经常安静地更新(通过 MapControl.ZoomLevelChanged-Event)并在该过程中被清除和重新填充 - 这可能是个问题吗?

通过 xaml 绑定看起来像这样:

 <maps:MapControl
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    [...]>
    <maps:MapItemsControl ItemsSource="{x:Bind Path=MapDirectionOverlay, Mode=OneWay}"/>
</maps:MapControl>

有什么建议吗?

Removing items to that collection is working too, but seemingly only within that collection- the visual representation on my MapControl does not react to removing elements.

ObservableCollection 表示一个动态数据集合,在添加、删除项目或刷新整个列表时提供通知。因此,如果您添加或删除项目,绑定的集合和 ItemsSouce 应该反映更新。

由于我不知道你是如何删除项目的,通过使用 ObeservableCollection 的删除方法,例如 Remove,RemoveAt and RemoveItem,它们应该可以很好地删除项目以及删除相应的项目地图.

但是如果你只是将ObeservableCollection设置为nullItemsSouce没有影响。在这种情况下你需要设置ItemsSouce 20=] 手动设置为空,但不推荐这样做。

由于使用 Clear-Method 没有成功,我尝试使用 ObservableCollection 的其他删除方法并最终奏效。

最后,这是我使用的解决方法:

private new void Clear()
{
    for (int i = this.Count - 1; i >= 0; i--)
    {
        this.RemoveAt(i);
    }
}

毕竟我还是不明白,为什么简单的 Clear 不起作用,因为它仍然应该引发 NotifyCollectionChangedAction。 (如果我错了请纠正我)