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 3780740
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:51:15+00:00 2026-05-19T10:51:15+00:00

Im struggling with Observable collections and using it to add pushpins onto a silverlight

  • 0

Im struggling with Observable collections and using it to add pushpins onto a silverlight bing map. Im trying to build up a collection here using Linq. But im getting the error under every “PushPinItems” instance in my code saying:

'observable_collection_test.Map.PushPinItems' is a 'field' but is used like a 'type' c:\users\dan\documents\visual studio 2010\Projects\observable collection test\observable collection test\Map.xaml.cs 26 38 observable collection test

Not sure whats going on here, am I declaring/constructing it wrong or something?
Im new to Observable collections (and most of c#!) so any help/advice welcome. Many thanks.

UPDATE:

This seems to be ok now, the above issue, but now its not binding my items to pushpins.
I have looked at the “PushPins = pushPinCollection;” method and all 143 items are in there with lat, long and location propertiess with the correct data- as per this breakpoint:

alt text

Maybe there is an issue with my XAML binding?

Here is the updated code:

  namespace observable_collection_test
 {
public partial class Map : PhoneApplicationPage
{

    private ObservableCollection<SItem2> _PushPins;

    public event PropertyChangedEventHandler PropertyChanged;

    public Map()
    {
        InitializeComponent();

        getItems();
    }

    public ObservableCollection<SItem2> PushPins
    {
        get
        {
            return _PushPins;
        }


        private set
        {
            _PushPins = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("PushPins"));
            }


        }
    }
    private GeoCoordinate _location;

    public GeoCoordinate Location
    {
        get { return _location; }
        set
        {
            if (_location != value)
            {
                _location = value;
                               }
        }
    }

    private string _pinSource;

    public string PinSource
    {
        get { return _pinSource; }
        set
        {
            if (_pinSource != value)
            {
                _pinSource = value;
                                }
        }
    }

    public void getItems()
    {
         var document = XDocument.Load("ListSmall.xml");

         if (document.Root == null)
            return;

          var xmlns = XNamespace.Get("http://www.blahblah.co.uk/blah");

         var events = from ev in document.Descendants("item")
          select new
          {
           Latitude = Convert.ToDouble(ev.Element(xmlns + "Point").Element(xmlns + "lat").Value),
            Longitude = Convert.ToDouble(ev.Element(xmlns + "Point").Element(xmlns + "long").Value),

         };

         ObservableCollection<SItem2> pushPinCollection = new ObservableCollection<SItem2>();

          foreach (var ev in events)

                         {
                           SItem2 PushPin = new SItem2
                (                    ev.Latitude, ev.Longitude)
            {

            };

            pushPinCollection.Add(PushPin);

        }
        PushPins = pushPinCollection;


    }

other class:

namespace observable_collection_test
 {

public class SItem2
    {
    //public DateTimeOffset Date { get; set; }
    //public string Title
    //{ get; set; }
    public double Latitude
    { get; set; }
    public double Longitude
    { get; set; }
    public GeoCoordinate Location
    { get; set; }
    //public Uri Link { get; set; }


    public SItem2(//string Title, 
        double Latitude, double Longitude)
    {
        //this.Date = Date;
        //this.Title = Title;
        this.Latitude = Latitude;
        this.Longitude = Longitude;
        //this.Location = Location;
        //this.Link = Link;
    }
}

Bit of XAML concerning adding pins to map:

      <my:Map ZoomBarVisibility="Visible" ZoomLevel="10" CredentialsProvider="AhqTWqHxryix_GnWER5WYH44tFuutXNEPvFm5H_CvsZHQ_U7-drCdRDvcWSNz6aT"  Height="508" HorizontalAlignment="Left" Margin="0,22,0,0" Name="map1" VerticalAlignment="Top" Width="456">
                                        <my:MapItemsControl ItemsSource="{Binding PushPins}" >
                <my:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <my:Pushpin Background="Aqua" Location="{Binding Location}" ManipulationCompleted="pin_click">
                        </my:Pushpin>
                    </DataTemplate>
                </my:MapItemsControl.ItemTemplate>
            </my:MapItemsControl>

        </my:Map> 

It would also be good to know if I am approaching the pushpin binding to the maps in the right way.

  • 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-19T10:51:16+00:00Added an answer on May 19, 2026 at 10:51 am

    It looks as if this is because you have used x:Name="PushPinItems" in your XAML which is the same name as one of your types, so when you think you are referencing your PushPinItems type in your codebehind, you are actually referencing the field that VS has generated for you from your XAML that represents that Pushpin instance. You could use a different x:Name in your XAML.

    Update

    Ok, I see the issue 🙂 I haven’t worked with the Bing maps control before, but looking at http://forums.silverlight.net/forums/t/197631.aspx (second post down), you need to set the map controls MapItemsControl property. The ItemsSource property here should be bound to your ObservableCollection of a custom type which contains properties such as Name and Location. You can then populate this collection with instances of this custom type (in the post they have used MapData as the type name).

    You can also get more examples and source code at http://www.microsoft.com/maps/isdk/silverlight/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Struggling with Bing's json request (bing search, not map), I am getting an error
I am using teleriks gridview in an mvvm silverlight project. I am struggling to
Struggling here... I am trying to have views displayed during specific periods in a
im struggling with syntax here: hopefully this question is v simple, im just miising
I'm struggling to find the right terminology here, but if you have jQuery object...
Struggling with onchange for JQuery Datetime plugin: http://plugins.jquery.com/project/datetime I am using the following code.
Struggling with the basics here. I want to setup an array, and fill it
Struggling a bit on this... I'm using crontab for a lot of todo list
Struggling to parse this JSON response from http://api.twitter.com/1/trends/current.json using foreach ($json_output->trends[0] as $trend )
I'm struggling with my first simple hello world RX application. I'm using VS2010 RC,

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.