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

  • Home
  • SEARCH
  • 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 9078061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:31:37+00:00 2026-06-16T19:31:37+00:00

This is my C# code, now it’s showing data in console. class PlaceViewModel {

  • 0

This is my C# code, now it’s showing data in console.

class PlaceViewModel
    {

        public List<Vantaa.IntroPage.Place> Places;
    }       

public class Place
            {
                public string id { get; set; }
                public string title { get; set; }
                public string latitude { get; set; }
                public string longitude { get; set; }
                public string www { get; set; }
            }

        public class RootObject
        {
            public List<Place> Places { get; set; }
        }

    protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            WebClient webClient = new WebClient();
            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
            webClient.DownloadStringAsync(new Uri("http://mobiilivantaa.lightscreenmedia.com/api/place"));
        }

        private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);

            foreach (var book in rootObject.Places)
            {
                System.Diagnostics.Debug.WriteLine(book.id);
            }
            this.DataContext = new PlaceViewModel
                 {
                      Places = rootObject.Places
                 };
            }

What should I do with xaml file in order to show the data in textblock ?

This is my current xaml code. It’s surely not working. I really have no idea.

<ListBox ItemsSource="{Binding Places}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <TextBlock Text="{Binding Path=id}" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
  • 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-06-16T19:31:38+00:00Added an answer on June 16, 2026 at 7:31 pm

    Your class-code looks good so now it’s just a matter of binding the results to the view. You are returning a list of objects so you should use a control that supports showing multiple items. Of course you could concatenate all the id’s of the books to one string and show it in a label. But this is not how it’s done. What you should do is add a ListBox control to the XAML and create a DataTemplate inside it. This way you set the way items will be displayed.

    Create a class that will be the ViewModel for your XAML-page. This class will have a property ‘Places’ (type: List<Place>). In the OnNavigatedTo-event when getting all the data is done, fill the ViewModel and bind and bind it to the DataContext of the XAML:

    this.DataContext = new YourViewModel { Places = rootObject.Places };
    

    This way you can grab all the objects from the ViewModel in your XAML:

    <ListBox ItemsSource="{Binding Places}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock Text="{Binding Path=id}" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    Edit:

    Here’s a working example:

    XAML:

    <Grid>
        <ListBox ItemsSource="{Binding Places}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=ID}" />
                        <TextBlock Text="{Binding Path=Title}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    

    Place.cs:

    public class Place
    {
        public string ID { get; set; }
        public string Title { get; set; }
        public string Latitude { get; set; }
        public string Longitude { get; set; }
        public string Web { get; set; }
    }
    

    MainViewModel.cs:

    public class MainViewModel
    {
        public MainViewModel()
        {
            Places = new List<Place>();
        }
    
        public List<Place> Places { get; set; }
    }
    

    Sample repository (you should have your own):

    public static List<Place> FetchData()
    {
        var lst = new List<Place>();
    
        lst.Add(new Place { ID = "1", Title = "One", Latitude = "111", Longitude = "111", Web = "www......" });
        lst.Add(new Place { ID = "2", Title = "Two", Latitude = "222", Longitude = "222", Web = "www......" });
        lst.Add(new Place { ID = "3", Title = "Three", Latitude = "333", Longitude = "333", Web = "www......" });
        lst.Add(new Place { ID = "4", Title = "Four", Latitude = "444", Longitude = "444", Web = "www......" });
    
        return lst;
    }
    

    MainWindow.xaml.cs:

    public MainWindow()
    {
        InitializeComponent();
        //This is where the magic happens
        //Fill the viewModel with the data
        var viewModel = new MainViewModel { Places = Repository.FetchData() };
        //Assign the viewModel with the data to the DataContext
        //The bindings will be automatically done in the XAML
        DataContext = viewModel;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED CODE: Now, I have this code: <h2>Testing</h2> <input type=checkbox name=fruit1 id=id1 class=box>Banana<br /><br
EDIT: This code now works correctly, I only left it in case someone finds
In Python I have this code: now = datetime.now().isoformat() if . not in now:
I'm using this code now echo $form->input('username'); How do I make sure the label
I have this code ,now can anyone reply s what happens to the lock
I have this code right now to get the row value from jquery grid..
this is my code for now: SELECT id, number FROM Media WHERE user =
This code used to return my local ip address as 192.xxx.x.xxx but now it
Now i'm using this code: User has_one User_extra User => :username, :email, :crypted_password, :salt,
Now i ve got this code: -(void)getContacts{ ABAddressBookRef currentAddressBook = ABAddressBookCreate(); if (currentAddressBook) {

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.