2011-05-14 90 views
1

我有以下xaml將類LocationCollection的一個實例綁定到類MapPolyline的一個實例。必應地圖路線多義線不能從地圖中移除

<Microsoft_Phone_Controls_Maps:MapPolyline Stroke="Green" 
              Locations="{Binding Points}" 
              StrokeThickness="6" 
              Opacity="0.7" /> 

Points屬性在視圖模型定義爲:

public LocationCollection Points 
{ 
    get 
    { 
     return this.points; 
    } 
    set 
    { 
     this.SetPropertyAndNotify(ref this.points, value, "Points"); 
    } 
} 

現在,當我設置Points屬性如預期的那樣顯示路徑線,但是當我想用下面的代碼刪除行該行仍然顯示 - 儘管我創建了一個新的空LocationCollection類並通知該屬性已更改。

任何人都知道爲什麼路線不被刪除?

this.Points = new LocationCollection(); 

回答

0

答案是集設置一個新的實例或完全清除當前的收集是錯誤的,我所要做的就是刪除所有,但在集合中的第一項。

例如

private void ResetPoints() 
{ 
    if (this.Points.Count() > 0) 
    { 
     var firstPoint = this.Points.First(); 
     this.Points.Clear(); 
     this.Points.Add(firstPoint); 
    } 
} 
0

創建與此

MapLayer route_layer = new MapLayer(); 

航線層創建MapPolyline線如

MapPolyline routeLine = new MapPolyline() 
     { 
      Locations = locs, 
      Stroke = new SolidColorBrush(c), 
      StrokeThickness = 5 
     }; 

添加到您的路線層,然後映射與此

route_layer.Children.Add(routeLine); 
MyMap.Children.Add(route_layer); 

從您的地圖中刪除

MyMap.Children.Remove(route_layer);