I’m using the Bing maps API for Silverlight and need to cycle through a selection of pushpins on the map and perform some formatting if the pins name is not equal to a value elsewhere in the code.
Here is the function:
private void deselectAllPins(MapLayer mainMapLayer)
{
foreach (UIElement ui in mainMapLayer.Children)
if (ui is SitePushpin)
{
SolidColorBrush scb = new SolidColorBrush(Colors.Red);
if (ui.GetValue(SitePushpin.SiteName).ToString() != hiddenShortName.Text)
{
....formatting
}
}
}
The ‘SitePushpin’ is declared as:
public class SitePushpin : Pushpin
{
public string SiteName { get; set; }
public SitePushpin(Color Bg)
{
this.Name = Guid.NewGuid().ToString();
SolidColorBrush scb = new SolidColorBrush(Bg);
this.Background = scb;
}
}
My issue comes in at the if statement with the ui.GetValue. It is unable to see the SiteName attribute and comes up with the error
“an object reference is required for the nonstatic field”
Any ideas how I can get it to see this value?
Many thanks
Cap
Property
SiteNameis an instance property, not atype/staticso you should have instance of theSitePushpinclass and then accessSiteNameproperty.SO