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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:02:03+00:00 2026-05-20T18:02:03+00:00

Ok, I’m no newbie at programming or C# as such, I just can’t seem

  • 0

Ok, I’m no newbie at programming or C# as such, I just can’t seem to get WPF’s databinding straight in my head. My colleagues are raving about it (and yes, I will ask them as well) but right now I’m stumped.

Here’s what I’d like to do for starters:

As an example I’ve got a list of things like this:

List<Thing> thingList = Source.getList();

Now normally I’d go

foreach(Thing t in thingList)
{
    //add thing to combobox
}

But from what I can gather is that I can somehow not do this but use a databinding to populate the combobox for me.

What I can’t seem to get is where do I put the ‘thingList’? Do I make it a separate property somewhere? Where do I put that property?

I feel very stupid at the moment, as I’ve been struggling with this for a while now and I can’t find any examples out there that make me understand this – probably very simple – concept.

Anyone out there willing to help me or point me at some step-by-step guide I might have missed?

  • 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-20T18:02:04+00:00Added an answer on May 20, 2026 at 6:02 pm

    Use ObservableCollection<T> for databinding in WPF. Where T is your class. See example below

    public class NameList : ObservableCollection<PersonName>
    {
        public NameList() : base()
        {
            Add(new PersonName("A", "E"));
            Add(new PersonName("B", "F"));
            Add(new PersonName("C", "G"));
            Add(new PersonName("D", "H"));
        }
      }
    
      public class PersonName
      {
          private string firstName;
          private string lastName;
    
          public PersonName(string first, string last)
          {
              this.firstName = first;
              this.lastName = last;
          }
    
          public string FirstName
          {
              get { return firstName; }
              set { firstName = value; }
          }
    
          public string LastName
          {
              get { return lastName; }
              set { lastName = value; }
          }
      }
    

    Now in XAML. Go to resource tag

    <Window
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
      xmlns:c="clr-namespace:SDKSample"
    
      x:Class="Sample.Window1"
      Width="400"
      Height="280"
      Title="MultiBinding Sample">
    
      <Window.Resources>
        <c:NameList x:Key="NameListData"/>
      </Window.Resources>
    
    
    <ListBox Width="200"
             ItemsSource="{Binding Source={StaticResource NameListData}}"  // Name list data is declared in resource
             ItemTemplate="{StaticResource NameItemTemplate}"
             IsSynchronizedWithCurrentItem="True"/>
    

    xmnls:c will give you option to choose the class. Here you can choose c,d ,e x whatever but be sure it should be used earlier

    • 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.