Note that there are some explanatory texts on larger screens.

plurals
  1. POObservable collection issues
    primarykey
    data
    text
    <p>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: </p> <pre><code>'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 </code></pre> <p>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.</p> <p><strong>UPDATE:</strong></p> <p>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:</p> <p><img src="https://i.stack.imgur.com/dOnnK.jpg" alt="alt text"></p> <p>Maybe there is an issue with my XAML binding?</p> <p>Here is the updated code:</p> <pre><code> namespace observable_collection_test { public partial class Map : PhoneApplicationPage { private ObservableCollection&lt;SItem2&gt; _PushPins; public event PropertyChangedEventHandler PropertyChanged; public Map() { InitializeComponent(); getItems(); } public ObservableCollection&lt;SItem2&gt; 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&lt;SItem2&gt; pushPinCollection = new ObservableCollection&lt;SItem2&gt;(); foreach (var ev in events) { SItem2 PushPin = new SItem2 ( ev.Latitude, ev.Longitude) { }; pushPinCollection.Add(PushPin); } PushPins = pushPinCollection; } </code></pre> <p>other class:</p> <pre><code>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; } } </code></pre> <p>Bit of XAML concerning adding pins to map:</p> <pre><code> &lt;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"&gt; &lt;my:MapItemsControl ItemsSource="{Binding PushPins}" &gt; &lt;my:MapItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;my:Pushpin Background="Aqua" Location="{Binding Location}" ManipulationCompleted="pin_click"&gt; &lt;/my:Pushpin&gt; &lt;/DataTemplate&gt; &lt;/my:MapItemsControl.ItemTemplate&gt; &lt;/my:MapItemsControl&gt; &lt;/my:Map&gt; </code></pre> <p>It would also be good to know if I am approaching the pushpin binding to the maps in the right way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload