ここでの最初の質問です。これまでのところ、回答を読むだけで大きな助けになりました。これは私が答えを見つけることができなかったものです。だからここに来る...
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
の に設定されてPositionChanged
いますGeoCoordinateWatcher
更新 (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);
}
}