locked
Accessing doubles in a MobileServiceTable

    Question

  • I have a MobileServiceTable (Azure web mobile service) that I am able to pull data from and then bind particular fields to a list view.

    What I want to do is take some geolocation information in in one of these records/object and pass it through to the map. I am not sure how to identify the doubles in the object and then pass them through to the map when an item in the list is selected, the code I have so far is as follows:

    Xaml

    <Grid Grid.Column="2" Margin="10,10,0,10" x:Name="SelectedUniView">
                <ListView x:Name="shortItems" IsSynchronizedWithCurrentItem="False" SelectionMode="Single">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <TextBlock x:Name="Groups" Text="{Binding Groups}"/>
                                <TextBlock x:Name="Towns" Text="{Binding Town}"/>
                                <TextBlock x:Name="Postcodes" Text="{Binding Postcode}"/>
                                <TextBlock x:Name="WebsiteName" Text="{Binding Website}"/>
                                <HyperlinkButton x:Name="Websites" NavigateUri="{Binding Website}" Content="Go Website" HorizontalAlignment="Left"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
    
            </Grid>
    
    bm:Map Credentials="map-key-credentials-are-here" x:Name="myMap"/>

    CS

        public class uniworld
        {
            public string Id { get; set; }
            
            [JsonProperty(PropertyName = "ProviderName")]
            public string ProviderName { get; set; }
    
            [JsonProperty(PropertyName = "Town")]
            public string Town { get; set; }
    
            [JsonProperty(PropertyName = "Postcode")]
            public string Postcode { get; set; }
    
            [JsonProperty(PropertyName = "Groups")]
            public string Groups { get; set; }
    
            [JsonProperty(PropertyName = "Website")]
            public Uri Website { get; set; }
    
            [JsonProperty(PropertyName = "Latitude")]
            public double Latitude { get; set; }
    
            [JsonProperty(PropertyName = "Longitude")]
            public double Longitude { get; set; }
    
        }
     private void InitializeMap()
            {
                myMap.Center = new Location(shortItems.SelectedValue.Latitude, shortItems.SelectedValue.Longitude);
                myMap.ZoomLevel = 12;
                myMap.MapType = MapType.Road;
            }
    The two areas that are new Locations 'shortItems.SelectedValue.Latitude' is where I am stuck, im thinking that I probably have to some sort of loop to write the values into public doubles, but im hoping there is a more elegant way.
    Wednesday, February 12, 2014 2:29 PM

Answers

  • SelectedValue and SelectedItem are of type 'object', not 'uniworld'. Try this code:

    uniworld selected = (uniworld)shortItems.SelectedItem;
    myMap.Center = new Location(selected.Latitude, selected.Longitude);

    Wednesday, February 12, 2014 3:03 PM