2016-05-17 16 views
0

MapControlに線を描画する必要があります。仕事doesnの `tMapControlの拡張C#UWP

<Maps:MapControl x:Name="mapMain" 
         MapServiceToken="{StaticResource MapServiceTokenString}" 
         RenderTransformOrigin="0.5,0.5" 
         Margin="0,0,0,0" 
         extentions:PolyLineMapControl.ItemsCollection="{Binding mapViewModel.PointsOfNodes}"> 
      <Maps:MapItemsControl x:Name="ItemsChanged" 
        ItemsSource="{x:Bind mapViewModel.PointsOfNodes, Mode=OneWay}"> 
       <Maps:MapItemsControl.ItemTemplate> 
        <DataTemplate x:DataType="data:PointOfNode"> 
         <StackPanel> 
          <Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
           <TextBlock Text="{x:Bind DisplayName, Mode=OneWay}"/> 
          </Border> 
          <Image Source="{x:Bind ImageSourcePath, Mode=OneWay}" 
            Maps:MapControl.Location="{x:Bind Location, Mode=OneWay}" 
            Maps:MapControl.NormalizedAnchorPoint="{x:Bind NormalizedAnchorPoint, Mode=OneWay}"> 
           <Image.Transitions> 
            <TransitionCollection> 
             <EntranceThemeTransition/> 
            </TransitionCollection> 
           </Image.Transitions> 
          </Image> 
         </StackPanel> 
        </DataTemplate> 
       </Maps:MapItemsControl.ItemTemplate> 
      </Maps:MapItemsControl> 
     </Maps:MapControl> 

私はsuccessfuly mapViewModelからポイントを得るが、拡張子:私は、XAMLビュー私のMapControlを持っています。

public class PolyLineMapControl 
{ 
public static readonly DependencyProperty ItemsCollectionProperty = DependencyProperty.RegisterAttached("ItemsCollection", typeof(List<PointOfNode>), typeof(PolyLineMapControl), new PropertyMetadata(default(List<PointOfNode>), OnItemsChanged)); 

     public static List<PointOfNode> GetItemsCollection(DependencyObject obj) 
     { 
      return (List<PointOfNode>)obj.GetValue(ItemsCollectionProperty); 
     } 

     public static void SetItemsCollection(DependencyObject obj, List<PointOfNode> value) 
     { 
      obj.SetValue(ItemsCollectionProperty, value); 
     } 

     private static void OnItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     { 
     //draw line 
     } 
} 

プロパティは完全に初期化されます。 setter、getter、チェンジャーのメソッドとプロパティでbrakpointを設定すると、これが検出されました。使用されるユーザーコントロール:

+0

[OK]を、私はセッターに行ったのObservableCollection スタートアプリaにリストを変更しました。しかしそれ以上はありません –

+0

あなたの 'PolyLineMapControl'は何のために使われていますか? –

+0

私はいくつかの点ObservableCollection をイメージのようにマップ上に置く。 MapItemsControlはこのコレクションにバインドしています。コレクションが変更されたとき、私はラインポイントを持っています。 –

答えて

0

1)TrackingMapControlを作成する:)点間のドローラインは

private void OnMapItemsPropertyChanged(DependencyObject sender, DependencyProperty dp) 
{ 
var mapItemsControls = sender as MapItemsControl; 
      var mapItemsSource = mapItemsControls?.ItemsSource as ObservableCollection<PointOfNode>; 

      if (mapItemsSource != null) 
      { 
       this.MainMap.MapElements.Clear(); 
       if (mapItemsSource.Count > 1) 
       { 
        for (var i = 0; i < mapItemsSource.Count - 1; i++) 
        { 
         this.LinePoints(mapItemsSource[i].Location, (mapItemsSource[i + 1]).Location); 
        } 
       } 
      } 
} 

3のMapControlするコレクション

private static readonly DependencyProperty.Register(
      "PointsOfNodes", 
      typeof(ObservableCollection<PointOfNode>), 
      typeof(MapControl), 
      new PropertyMetadata(new ObservableCollection<PointOfNode>())); 
     public ObservableCollection<PointOfNode> PointsOfNodes 
     { 
      get { return (ObservableCollection<PointOfNode>)this.GetValue(PointsOfNodesProperty); } 
      set { this.SetValue(PointsOfNodesProperty, value); } 
     } 

2)を作成する方法onChangeCollectionにしたDependencyPropertyでユーザーコントロールを作成MapIconControlポイントのテンプレートとしてTrackingMapControlで