1

这里的第一个问题,到目前为止,我在阅读答案时得到了很大的帮助。这是我找不到任何答案的东西。所以来了...

我们有一个MapItemsControl绑定到的 Bing Maps 地图ObservableCollection<Pushpin> Property。向集合中添加/删除项目时,地图会正确更新。

现在我的问题是:如何更新/绑定Pushpin集合内的位置,以便在不通过移动/缩放重绘地图的情况下反映在地图上?

这是 Map.xaml:

<phone:PhoneApplication ...
    DataContext="{Binding Source={StaticResource Locator}, Path=Main}">
    <maps:Map ...>
        <maps:MapItemsControl ItemsSource="{Binding MapItems}"/>
    </maps:Map>
</phone:PhoneApplication>

MainViewModel.xaml:

#region MapItems

#region MapItems Property

/// <summary>
/// The <see cref="MapItems" /> property's name.
/// </summary>
public const string MapItemsPropertyName = "MapItems";

private ObservableCollection<Pushpin> _MapItems =
    new ObservableCollection<Pushpin>();

/// <summary>
/// Sets and gets the MapItems property.
/// Changes to that property's value raise the PropertyChanged event. 
/// </summary>
public ObservableCollection<Pushpin> MapItems
{
    get
    {
        return _MapItems;
    }
    set
    {
        if (_MapItems == value)
        {
            return;
        }

        _MapItems = value;
        RaisePropertyChanged(MapItemsPropertyName);
    }
}

#endregion

#region OwnLocation

private Pushpin OwnLocation;

private void InitializeOwnLocation()
{
    OwnLocation = new Pushpin()
    {
        Style = App.Current.Resources["OwnLocationStyle"] as Style
    };
    Binding b = new Binding {
        Path = new PropertyPath("LastKnownLocation")
    };
    OwnLocation.SetBinding(Pushpin.LocationDependencyProperty, b);
    MapItems.Add(OwnLocation);
}

#endregion

...

#endregion

LastKnownLocation被设置PositionChangedGeoCoordinateWatcher


更新 (30.5.2012 20.35)。LastKnownLocation财产的实施。

/// <summary>
/// The <see cref="LastKnownLocation" /> property's name.
/// </summary>
public const string LastKnownLocationPropertyName = "LastKnownLocation";

private GeoCoordinate _LastKnownLocation;

/// <summary>
/// Sets and gets the LastKnownLocation property.
/// Changes to that property's value raise the PropertyChanged event. 
/// </summary>
public GeoCoordinate LastKnownLocation
{
    get
    {
        return _LastKnownLocation;
    }

    private set
    {
        if (_LastKnownLocation == value)
        {
            return;
        }

        var oldValue = _LastKnownLocation;
        _LastKnownLocation = value;
        Settings["LastKnownLocation"] = _LastKnownLocation;
        RaisePropertyChanged(LastKnownLocationPropertyName, oldValue, value, true);
    }
}
4

2 回答 2

0

x:Name= myMap on map Control

当您想重新绑定地图图钉时

设置 myMap.Children.Clear()

然后重新添加您的 Pin 图。

您可以通知您的数据更改

于 2012-10-29T07:16:13.367 回答
0

正如我在长时间谷歌搜索后评论的那样,我终于找到了一个似乎不再可用的解决方法。诀窍是在更改后调用SetView地图视图Pushpin.Location

于 2015-01-27T07:14:24.210 回答