Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:55:19+00:00 2026-05-25T18:55:19+00:00

I can’t seem to get my head around this pushpin binding and I need

  • 0

I can’t seem to get my head around this pushpin binding and I need some more help.

I have the follow code to parse from XML and split a coordinate string in Lat, Lon and Alt. What I want to do is to display these points as pushpins on my bing maps.

I thought that by creating a new object of Geocoordinates in Location I could then bind that to my pushpin location, but nothing is displayed. Where am I going wrong?

namespace Pushpins_Itemsource
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {

            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

            WebClient busStops = new WebClient();
            busStops.DownloadStringCompleted += new DownloadStringCompletedEventHandler(busStops_DownloadStringCompleted);
            busStops.DownloadStringAsync(new Uri("http://www.domain/source.xml"));

        }

        void busStops_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
                return;



            var busStopInfo = XDocument.Load("Content/BusStops2.xml");

            var Transitresults = from root in busStopInfo.Descendants("Placemark")
                                 let StoplocationE1 = root.Element("Point").Element("coordinates")
                                 let nameE1 = root.Element("name")

                                 select new TransitVariables

                                     (StoplocationE1 == null ? null : StoplocationE1.Value,
                                              nameE1 == null ? null : nameE1.Value);

        }

        // Add properties to your class
        public class TransitVariables
        {
            // Add a constructor:
            public TransitVariables(string stopLocation, string name)
            {
                this.StopLocation = stopLocation;
                this.Name = name;
                if (!string.IsNullOrEmpty(StopLocation))
                {
                    var items = stopLocation.Split(',');
                    this.Lon = double.Parse(items[0]);
                    this.Lat = double.Parse(items[1]);
                    this.Alt = double.Parse(items[2]);
                }
            }

            public string StopLocation { get; set; }
            public string Name { get; set; }
            public double Lat { get; set; }
            public double Lon { get; set; }
            public double Alt { get; set; }

        }

        public class TransitViewModel
        {
            ObservableCollection<TransitVariables> Transitresults ;
            public ObservableCollection<TransitVariables> TransitCollection
            {
                get { return Transitresults; }
            }

        }
    }
}

XAML looks like this.

<my:Map ZoomLevel="6" Height="500" HorizontalAlignment="Left" Margin="0,6,0,0" CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" Name="Map" VerticalAlignment="Top" Width="456">
    <my:MapItemsControl ItemsSource="{Binding TransitVariables}" Height="494">
        <my:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <my:Pushpin Location="{Binding Location}"  />
            </DataTemplate>
        </my:MapItemsControl.ItemTemplate>
    </my:MapItemsControl>
</my:Map>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:55:19+00:00Added an answer on May 25, 2026 at 6:55 pm

    From the code you’ve posted, it looks like the issue is that the ItemsSource for MapsItemsControl is not databound to a collection. It’s bound to a type.

    Okay, Databinding doesn’t really work unless you define a DataContext etc. You’re sort of mixing and matching paradigms here. I think it would be good to learn MVVM and Databinding at somepoint, but for now, I think it’s okay to just do a quick and dirty approach.

    The easiest way to get this working is to just assign the ItemSource.

    To do this, first name your MapsItemControl, so you can access it in the codebheind.

    <my:Map ZoomLevel="6" Height="500" HorizontalAlignment="Left" Margin="0,6,0,0" CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" Name="Map" VerticalAlignment="Top" Width="456">
    <my:MapItemsControl x:Name="RhysMapItems" ItemsSource="{Binding TransitVariables}" Height="494">
        <my:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <my:Pushpin Location="{Binding Location}"  />
            </DataTemplate>
        </my:MapItemsControl.ItemTemplate>
    </my:MapItemsControl>
    

    Inside your download string complete handler, you should be able to do this:

        void busStops_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
                return;
    
    
    
            var busStopInfo = XDocument.Load("Content/BusStops2.xml");
    
            var Transitresults = from root in busStopInfo.Descendants("Placemark")
                                 let StoplocationE1 = root.Element("Point").Element("coordinates")
                                 let nameE1 = root.Element("name")
    
                                 select new TransitVariables
    
                                     (StoplocationE1 == null ? null : StoplocationE1.Value,
                                              nameE1 == null ? null : nameE1.Value);
    
           // This should bind the itemsource properly
           // Should use Dispatcher actually...see below
           RhysMapItems.ItemsSource = Transitresults.ToList();
        }
    

    Now, the one caveat here, is that it’s very likely that your DownloadStringCompleted handler will be invoked on a different thread than the UI thread.

    In which case you’ll need to make use of the Dispatcher.BeginInvoke() to modify the ItemSource property.

    this.RootVisual.Dispatcher.BeginInvoke( _=> { RhysMapItems.ItemsSource = Transitresults.ToList();});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me? What should be the datatype for this type -07:00:00 of
Can't figure out how to do this in a pretty way : I have
Can anyone help me trying to find out why this doesn't work. The brushes
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can i get the source code for a WAMP stack installer somewhere? Any help
I have some data like this: 1 2 3 4 5 9 2 6
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can I get a 'when to use' for these and others? <% %> <%#
Can you suggest some good MVC framework for perl -- one I am aware

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.