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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:58:34+00:00 2026-06-08T21:58:34+00:00

I am still very new and trying my first serious data binding. I have

  • 0

I am still very new and trying my first serious data binding. I have read a lot about how it works, am just struggling with this concrete example. I have tried to read all links I could find on this, but most sources tend to be a bit imprecise at key spots. So here goes:

-My Application generates dynamically a variable ‘PlayerList’ of type ‘List’, where ‘Player’ is a complex object.

-I want to display this in a ListBox via Binding. Obvoiusly, since Player is a complex Object I want to create a DataTemplate for it. So I have something like this in the ‘Window1.xaml’:

<ListBox 
    Name="ListBox_Players" 
    ItemsSource="{Binding Source={StaticResource PlayerListResource}}"
    ItemTemplate="{StaticResource PlayerTemplate}">
</ListBox>  

and something like this in the ‘App.xaml’:

<DataTemplate x:Key="PlayerTemplate">  <!-- DataType="{x:Type Player}" --> 
    <StackPanel Orientation="Horizontal">
      <TextBlock Text="{Binding Path=name}"/>
      <TextBlock Text=", "/>
      <TextBlock Text="{Binding Path=nrOfTabls}"/>
    </StackPanel>
</DataTemplate>

Of course, this template will become more verbose later. So as you see above, I have tried to create a resource for the PlayerList variable, but have not managed yet, i.e., smthn. like this

<src: XXX x:Key="PlayerListResource"/>

where for XXX as I understand it I should enter the class of the Resource variable. I tried

List<Player>, List<src:Player>

etc., but obv. XAML has trouble with the ‘<,>’ characters.

I also have another problem: By not declaring a resource but by direct binding (i.e., in C# writing “ListBox_Players.ItemsSource=PlayerList;”) and deleting the ‘ItemTemplate’ declaration and overwriting the ToString() method of the Player class to output the name of the Player I have managed to see that the binding works (i.e., I get a list of Player names in the ListBox). But then, if I insert the template again, it displays only ‘,’my Template does not work!

  • 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-08T21:58:36+00:00Added an answer on June 8, 2026 at 9:58 pm

    The fact that you’re getting just commas without anything else suggests to me that either the names of Player members do not match the names in Path= in the DataTemplate (I had this problem at one point), or the relevant Player members are inaccessible.

    I just tested what you’ve shown of your code so far, and it seemed to work fine. The only change I made was change this line:

    ItemsSource="{Binding Source={StaticResource PlayerListResource}}"
    

    to this line:

    ItemsSource = "{Binding}"
    

    This tells the program that it’ll get the ItemsSource at run time.

    My Player class was:

    class Player {
        public string name { get; set; }
        public int nrOfTabls { get; set; }
    }
    

    and my MainWindow.xaml.cs was:

    public partial class MainWindow : Window {
        private ObservableCollection<Player> players_;
    
        public MainWindow() {
            InitializeComponent();
    
            players_ =new ObservableCollection<Player> () {
                new Player() {
                    name = "Alex",
                    nrOfTabls = 1,
                },
                new Player() {
                    name = "Brett",
                    nrOfTabls = 2,
                },
                new Player() {
                    name="Cindy",
                    nrOfTabls = 231,
                }
            };
    
            ListBox_Players.ItemsSource = players_;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still very new to Android, but I am trying to keep up by
I'm still very new to prolog, and am trying to wrap my head around
Alright well I'm still a very new coder in Greasemonkey and just know a
I am trying to just remove the first line of about 5000 text files
Allright som first of im very new to android programming and was trying to
I'm still very new at programming, and our local SSIS genius isn't here today
I am still very new to the MVC framework, but I managed to create
I am very new to ExtJS and still going through the Docs in Sencha
EDIT: Updated with suggestions from Bill Karwin below. Still very slow. I'm trying to
I have a very annoying problem and I'm trying to find the simplest solution

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.