This project has moved. For the latest updates, please go here.

Add dynamically layers

Oct 16, 2013 at 4:45 PM
I'm trying to do it in:

In the XAML, I defined a datatemplate:
<DataTemplate x:Key="Templatecolor21">
    <map:MapPolyline Locations="{Binding Locations}" Stroke="Purple" StrokeThickness="3"/>
</DataTemplate>
In the .cs file:
CustomItemCollection newItemCollection = new CustomItemCollection();
MapItemsControl newMapItemControl = new MapItemsControl();
newMapItemControl.ItemsSource = newItemCollection;
newMapItemControl.IsSynchronizedWithCurrentItem = true;
newMapItemControl.Visibility = Visibility.Visible;
newMapItemControl.ItemTemplate = (DataTemplate)this.Resources[Templatecolor21];

//layer1CustomItemCollection is a Global List<ICollection<object>>
//layer1MapItems is a Global List<MapItemsControl>

layer1CustomItemCollection.Add(newItemCollection);
layer1MapItems.Add(newMapItemControl);
After that I had Polyline to newItemCollection but I don't see nothing on the map.

Thanks for helping me out.
Vincent
Coordinator
Oct 16, 2013 at 5:34 PM
The item type in CustomItemCollection has a public Locations property?
The MapItemsControls from layer1MapItems are added to a Map or MapPanel somewhere?

Please take a look at the sample application provided with the project to get an idea how to add MapPolylines to a MapItemsControl.
Marked as answer by Pat001 on 10/16/2013 at 2:36 PM
Oct 16, 2013 at 9:36 PM
Hi ClemensF,
The sample provided on this website is great, I was able to add easily new layers with different shapes.

But, to do it dynamically, I had some trouble. I had only 1 line missing in my code to make it works. When you said "The MapItemsControls from layer1MapItems are added to a Map or MapPanel somewhere? ", I noticed what I fordot.
map.Children.Add(newMapItemControl);
When I add this line, my new layer is added to the map and I see it now.

Thanks.
Marked as answer by Pat001 on 10/16/2013 at 2:36 PM
Coordinator
Oct 16, 2013 at 10:03 PM
Edited Oct 16, 2013 at 10:03 PM
The problem is you're to fast with asking for help. Rethink and try once more on your own before posting all your trivial problems here.