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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:21:54+00:00 2026-05-27T00:21:54+00:00

I´ve got two classes, Handy (It´s a Model with ID, Name and Year) and

  • 0

I´ve got two classes, Handy(It´s a Model with ID, Name and Year) and a HandyRepository.

My HandyRepository looks like this:

 private IList<Handy> list = new List<Handy>(new Handy[] {
        new Handy{ ID=1, Name="Nokia ", Jahr=1999},
        new Handy{ ID=2, Name="HTC m", Jahr=2333},
        new Handy{ ID=3, Name="Samsung", Jahr=2134} });


    public IEnumerable<Handy> GetList()
    {
        return this.list;
    }

Now, i want that data to a ListBox in my wpf-application, without writing any code in the code-behind file.

My attempt:

    xmlns:local="clr-namespace:Handy"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.DataContext>
        <local:Handy></local:Handy>
    </Grid.DataContext>

    <ListBox Name="lbBinding" ItemsSource="{Binding Name}"></ListBox>
</Grid>

That doesn´t work. Do I have a basic error in reasoning? How can I solve this problem?

  • 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-27T00:21:54+00:00Added an answer on May 27, 2026 at 12:21 am

    You haven’t managed to bind ItemsSource to the actual collection. Firstly, you need to make a collection and give it a key by which it can be identified:

    <x:Array x:Key="HandyList" Type="{x:Type local:Handy}">
        <local:Handy Name="Nokia " Jahr="1999" ID="1" />
        <local:Handy Name="HTC m", Jahr="2333" ID="2" />
    </x:Array>
    

    The key can be any identifier you like.

    Then you need to tell the ListBox to look for that key:

    <ListBox ItemsSource="{StaticResource HandyList}" Name="lbBinding" />
    

    Unfortunately that won’t render entirely correctly, as you’ll get the default ToString() of the Handy class appearing in the ListBox, so you need to tell it how to render:

    <ListBox ItemsSource="{StaticResource HandyList}"
             Name="lbBinding"
             DisplayMemberPath="Name" />
    

    That will ensure it uses the Name property as the source of the string to render in the ListBox. You can do more complicated rendering by providing a custom DataTemplate if you need it.

    Of course, there are few real-world applications where you define your ItemsSource in the XAML. It’s more normal to bind to a property of the view’s DataContext. The simplest way to do that would be to add a property to the view itself in its codebehind:

    public List<Handy> HandyList { get; set; }
    

    Then set the view to be its own DataContext in its constructor, after the call to InitializeComponent():

    DataContext = this;
    

    Then you can bind ItemsSource in the XAML to {Binding Path=HandyList}. Don’t forget to construct the list and populate it, of course…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm battling with this assignment :) I've got two classes: Ocean and Grid. When
I have two classes: public class Article { private ISet<IdentNumber> identNumbers = new HashedSet<IdentNumber>();
I'll try and make this clear; I've got two classes; GPU(Object) , for general
I have got two classes, one a subclass of the other (say Animal and
I've got two Java projects, both generate Java classes based on a schema definition,
I've got two classes, ProductConfiguration and SubProduct. I want to replace the subproducts on
I've got two classes: public class A { B refToB; } public class B
I've got two classes in my MVC project Order and Product . Because Product
Let's say I've got two classes, each fully tested. There's duplication though, so I
I read other threads like this but they didn't work for me. I got

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.