MapPolygon trouble binding Points

2 posts, 0 answers
  1. James
    James avatar
    6 posts
    Member since:
    Nov 2013

    Posted 11 Nov 2013 Link to this post

    Hey guys,

    Currently I'm creating my map polygons programatically but want to move it over to xaml and I'm having a problem getting the polygons to show from my xaml.

    This is how I was doing it previously and it works fine:

    MapPolygon polygon = new MapPolygon()
    {
        Points = coll,
        Fill = new SolidColorBrush(fill),
        Stroke = new SolidColorBrush(stroke),
        StrokeThickness = 2,
        Tag = p
    };
     
    System.Xml.Linq.XElement xTextBlock = new System.Xml.Linq.XElement("TextBlock");
    xTextBlock.SetAttributeValue("Text", "Name: " + p.Name + "\n" + p.Type + " Name: " + p.OwnerName);
     
    DataTemplate template = (DataTemplate)XamlReader.Load(
        @"<DataTemplate
    xmlns=""http://schemas.microsoft.com/client/2007"">
    " + xTextBlock.ToString(System.Xml.Linq.SaveOptions.DisableFormatting)
           + "</DataTemplate>"
        );
     
    polygon.CaptionLocation = new Location(p.PointData[0].PointLatitude, p.PointData[0].PointLongitude);
    polygon.CaptionTemplate = template;
     
    shapeLayer.Items.Add(polygon);
    The new way I'm doing it is like this
    
    
    <UserControl x:Class="WIMMS.UI.Module.Main.Controls.SimplePolygonInfo"
        xmlns:local="clr-namespace:WIMMS.UI.Module.Main"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"            
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <Grid x:Name="LayoutRoot">
            <telerik:MapPolygon x:Name="MapPolygonItem" Points="{Binding PointData}" Fill="Red" Stroke="Red" StrokeThickness="2"/>
        </Grid>
    </UserControl>
    public partial class SimplePolygonInfo : UserControl
        {
            private IEventAggregator _events;
            private ICommonService _commonService;

            public SimplePolygonInfo(IEventAggregator events, ICommonService commonService)
            {
                InitializeComponent();
                _events = events;
                DataContext = this;
                _commonService = commonService;
            }

            public static readonly DependencyProperty pointsProperty =
    DependencyProperty.Register("PointData", typeof(LocationCollection), typeof(SimplePolygonInfo), new PropertyMetadata(new LocationCollection()));
     
            public LocationCollection PointData
            {
                get
                {
                    return (LocationCollection)GetValue(pointsProperty);
                }
                set
                {
                    SetValue(pointsProperty, value);
                }
            }
        }
    And the logic changes to this:
    SimplePolygonInfo polyInfo = _container.Resolve<SimplePolygonInfo>();
    polyInfo.PointData = coll;
    shapeLayer.Items.Add(polyInfo);
    Is it even possible to do it this way? If I do something such as add a text block above the map polygon I can see that.
    <Grid x:Name="LayoutRoot">
        <TextBlock Text="Test Text"/>
        <telerik:MapPolygon x:Name="MapPolygonItem" Points="{Binding PointData}" Fill="Red" Stroke="Red" StrokeThickness="2"/>
    </Grid>
    But can't see the polygon still. Thanks for the help
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 11 Nov 2013 Link to this post

    Hello James,

    The map shapes like the MapPolygon can be used within a data template as the root element only. So, your SimplePolygonInfo control should look like the following:
    <telerik:MapPolygon x:Class="MapPolygonControl.SimplePolygonInfo"
        Points="{Binding PointData}" Fill="Red" Stroke="Red" StrokeThickness="2">
        <telerik:MapPolygon.CaptionTemplate>
            <DataTemplate>
                <TextBlock Text="Test Text" />
            </DataTemplate>
        </telerik:MapPolygon.CaptionTemplate>
    </telerik:MapPolygon>
    using System.Windows;
    using Telerik.Windows.Controls.Map;
     
    namespace MapPolygonControl
    {
        public partial class SimplePolygonInfo : MapPolygon
        {
            public static readonly DependencyProperty pointsProperty =
                DependencyProperty.Register("PointData", typeof(LocationCollection), typeof(SimplePolygonInfo), new PropertyMetadata(new LocationCollection()));
      
            public SimplePolygonInfo()
            {
                InitializeComponent();
            }
     
            public LocationCollection PointData
            {
                get
                {
                    return (LocationCollection)GetValue(pointsProperty);
                }
                set
                {
                    SetValue(pointsProperty, value);
                }
            }
        }
    }

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top