我正在開發一個帶有MVVM Light和使用MapControl的PCL的windows phone 8.1(winRT)應用程序。 我遇到了MapControl Center屬性綁定的問題。 在應用程序初始化時,該屬性在ViewModel中設置並且地圖正確居中。Windows Phone 8.1中MapControl Center屬性的數據綁定
但是,當我更新ViewModel中的值時,映射不會重新居中,但如果將值綁定到文本塊,它將被正確更新。
XAML:
視圖模型的<Maps:MapControl BorderThickness="2" BorderBrush="Black"
x:Name="Map"
HorizontalAlignment="Right" Margin="0,45,0,0"
VerticalAlignment="Top"
Height="595" Width="400"
ZoomLevel="10"
LandmarksVisible = "False"
TrafficFlowVisible = "False"
PedestrianFeaturesVisible = "False"
Center="{Binding Path=ViewStoreModel.CenterPosition, Mode=OneWay, Converter={StaticResource NormalizedAnchorPointConverter}}"
MapServiceToken="{StaticResource MapServiceTokenString}">
<Maps:MapItemsControl x:Name="MapIcons" ItemsSource="{Binding ViewStoreModel.ListStoreSearch}" >
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate x:Name="Temp" >
<StackPanel Tapped="Image_Tapped" x:Name="MyStack" Maps:MapControl.Location="{Binding store_position, Converter={StaticResource GeoPointConvertCenter}}">
<Image x:Name="PinsImage" Source="ms-appx:///Assets/map-pin-button.png" />
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
</Maps:MapControl>
物業:
public Location CenterPosition
{
get
{
return _centerPosition;
}
set
{
Set(CenterPositionPropertyName, ref _centerPosition, value);
}
}
public class Location : ObservableObject
{
public const string latitudePropertyName = "latitude";
public const string longitudePropertyName = "longitude";
private double _latitude;
private double _longitude;
public double latitude
{
get
{
return _latitude;
}
set
{
Set(latitudePropertyName, ref _latitude, value);
}
}
public double longitude
{
get
{
return _longitude;
}
set
{
Set(longitudePropertyName, ref _longitude, value);
}
}
酒店中心是一個類型的GeoPoint所以我用一個轉換器,將其從自定義類的位置轉換。 Center是一個依賴屬性,所以它應該是可綁定的。
感謝您的幫助。
我試過這個,但沒有奏效。 – Gouar 2015-04-08 07:55:54