ComponentOne Maps for UWP
C1MapsFeatures / Vector Layer / Data Binding
In This Topic
    Data Binding
    In This Topic

    C1VectorLayer has two properties to support data binding:

    Data Binding Example 

    Suppose you have a collection of City objects:

    C#
    Copy Code
    public class City
      {
        public Point LongLat { get; set; }
        public string Name { get; set; }
      }
    

    The template defines how to create C1VectorPlacemark from the City class.

    Markup
    Copy Code
    <C1:C1Maps x:Name="maps" Foreground="LightGreen">
      <C1:C1Maps.Resources>
      <!-- Item template -->
         <DataTemplate x:Key="templPts">
           <C1:C1VectorPlacemark
             GeoPoint="{Binding Path=LongLat}" Fill="LightGreen" Stroke="DarkGreen"
             Label="{Binding Path=Name}" LabelPosition="Top" >
             <C1:C1VectorPlacemark.Geometry>
               <EllipseGeometry RadiusX="2" RadiusY="2" />
             </C1:C1VectorPlacemark.Geometry>
           </C1:C1VectorPlacemark>
         </DataTemplate>
      </C1:C1Maps.Resources>
      <C1:C1VectorLayer ItemsSource="{Binding}"
      ItemTemplate="{StaticResource templPts}" />
    </C1:C1Maps>
    
       

    Finally, you need to use some real collection as a data source.

    C#
    Copy Code
    City[] cities = new City[]
    {
        new City(){ LongLat= new Point(30.32,59.93), Name="Saint Petersburg"},
        new City(){ LongLat= new Point(24.94,60.17), Name="Helsinki"},
        new City(){ LongLat= new Point(18.07,59.33), Name="Stockholm"},
        new City(){ LongLat= new Point(10.75,59.91), Name="Oslo"},
        new City(){ LongLat= new Point(12.58,55.67), Name="Copenhagen"}
    }; 
    maps.DataContext = cities;