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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:50:22+00:00 2026-05-19T04:50:22+00:00

I’m unable to do a simple but yet tricky WPF binding in Silverlight 4

  • 0

I’m unable to do a simple but yet tricky WPF binding in Silverlight 4 (WP7 development)

I have the following code:

Class People{
    public string firstname;
    public string lastname;
}

Class DataSource{
    public static List<People> people; // consider this as a list filled with objects already
}

I’m trying to put the list of people into a ListBox, here’s the xaml I’ve tried:

            <ListBox x:Name="peoplelistbox" Margin="0,0,-12,0" ItemsSource="{Binding DataSource.people}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                      <StackPanel Margin="0,0,0,17" Width="432">
                            <TextBlock Text="{Binding firstname}" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding lastname}" TextWrapping="Wrap"/>
                      </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

But unfortunately my listbox remains empty. What am I doing wrong ?

Thank you in advance 🙂

Cheers,
Miloud B.

  • 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-19T04:50:22+00:00Added an answer on May 19, 2026 at 4:50 am

    Firstly you are using fields, where you should use public property (i.e. people, firstname and lastname). Convert people to a public property, like this:

    public static List<People> people { get; set; }
    

    Then, you need to bind the ItemsSource using x:Static markup, like this:

    <ListBox x:Name="peoplelistbox" Margin="0,0,-12,0">
       <ListBox.ItemsSource>
          <Binding Source="{x:Static local:DataSource.people}"/>
       <ListBox.ItemsSource/>
       ...
    

    PS: local is the xml namespace pointing to your DataSource class’s namespace. Also, your class too needs to be a public class.

    EDIT:
    For WP7, you need to declare the instance of the class in the resources and then you can use Path to point to the source. Like this:

    <phone:PhoneApplicationPage.Resources>
        <local:DataSource x:Key="dataSource"/>
    </phone:PhoneApplicationPage.Resources>
    ...
    <ListBox x:Name="peoplelistbox" Margin="0,0,-12,0" ItemsSource="{Binding Source={StaticResource dataSource}, Path=people}">
    

    PS: Again, your class needs to be public and must have a default constructor.

    EDIT:
    Here is a example which is working perfectly on my system. Check and see where are you making the mistake:

    namespace WindowsPhoneApplication1
    {
        public class People
        {
            public string firstname { get; set; }
            public string lastname { get; set; }
        }
    
        public class DataSource
        {
            public static List<People> people { get; set; }
    
            public DataSource() { }
    
            static DataSource()
            {
                people = new List<People> {new People {firstname = "Foo", lastname = "Bar"}};
            }
        }
    
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
            }
        }
    }
    

    Xaml (only the relevant portions):

    ...
    ...
    xmlns:local="clr-namespace:WindowsPhoneApplication1"
    ...
    ...
    <phone:PhoneApplicationPage.Resources>
        <local:DataSource x:Key="dataSource"/>
    </phone:PhoneApplicationPage.Resources>
    ...
    ...
    <ListBox x:Name="peoplelistbox" Margin="0,0,-12,0" ItemsSource="{Binding Source={StaticResource dataSource}, Path=people}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="0,0,0,17" Width="432">
                    <TextBlock Text="{Binding firstname}" TextWrapping="Wrap"/>
                    <TextBlock Text="{Binding lastname}" TextWrapping="Wrap"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.