Using ItemTemplateSelector

3 posts, 0 answers
  1. Madison
    Madison avatar
    2 posts
    Member since:
    Jun 2010

    Posted 11 Jan 2011 Link to this post


    I'm trying to get the ItemTemplateSelector of the InformationLayer to work, and am not succeeding.
    Initially I tried creating my layers dynamically in code as I needed them, but even when trying this other ways it does not seem to work.

    My template is (I will write more once I get this working)
    <DataTemplate x:Key="MapItemDataTemplate"
     <TextBlock Text="Hi"
      telerikMap:MapLayer.Location="{Binding Location}" 
       telerikMap:MapLayer.BaseZoomLevel="{Binding BaseZoomLevel}"
      telerikMap:MapLayer.ZoomRange="{Binding ZoomRange}" /> 
    My map definition is:
    <telerikDataVis:RadMap  x:Name="mapView" ZoomLevel="{Binding Zoom, Mode=TwoWay}" Center="{Binding Center, Mode=TwoWay}"                                
      CenterChanged="LocationRectChangedHandler" ZoomChanged="LocationRectChangedHandler"
         <telerikMap:InformationLayer x:Name="InformationLayer1"   Visibility="Collapsed"
           ItemsSource="{Binding FilteredItems}" /> 

    My CodeBehind:
    public MapView()
                // binding for DataContext (see note on InternalDataContextProperty)
                SetBinding(InternalDataContextProperty, new Binding());
                // set provider for maps
                this.mapView.Provider = new Telerik.Windows.Controls.Map.OpenStreetMapProvider();
                this.InformationLayer1.ItemTemplateSelector = new MyMapDataTemplateSelector() { mapView = this };
    private void mapView_InitializeCompleted(object sender, EventArgs e)
                this.InformationLayer1.DataContext = (DataContext as IMapViewModel).GetLayer("main");
                this.InformationLayer1.Visibility = Visibility.Visible;

    The data context I set contains the FilteredItems property.
    Please enlighten me
  2. Madison
    Madison avatar
    2 posts
    Member since:
    Jun 2010

    Posted 11 Jan 2011 Link to this post

    Sorry... forgot the DataTemplateSelector class

    public class MyMapDataTemplateSelector : MapSystem.MapDataTemplateSelector
           public MapView mapView { get; set; }
           public override DataTemplate SelectTemplate(object item, DependencyObject container)
               MapItemViewModel mapItem = item as MapItemViewModel;
               if (mapItem == null) return null;
               if (mapItem.ContextObject is PolylineMapItemViewModel)
                   return (mapView.Resources["PolylineMapItemDataTemplate"] as DataTemplate);
               if (mapItem.ContextObject is PolygonMapItemViewModel)
                   return (mapView.Resources["PolygonMapItemDataTemplate"] as DataTemplate);
               return (mapView.Resources["MapItemDataTemplate"] as DataTemplate);
  3. Andrey
    Andrey avatar
    1681 posts

    Posted 14 Jan 2011 Link to this post

    Hi Madison,

    It is quite difficult to reproduce your situation having just the parts of code you have provided. I am afraid there are many things missing (structure of the data context is unknown, description of the MapItemViewModel class is not provided, etc). I've created small test application which uses as much from your code as I can get, and replace other things with my own. All things seems work just fine. I've attached my sample project to the message. Please, compare it with your own.

    Kind regards,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top