In the previous video when we displayed the list box, you can see that we can see Yannick, Peter,
Maria, Mark, none of that.
But those are simple strings, right?
So we have a class called Person that consists out of multiple properties like age and name.
But in our program, the list box only shows a list of string, which is definitely a very, very primitive
data type that still gets used pretty often.
But most of the time you are working with more complex data.
Even though complex data most of the time always breaks down to at least strings and booleans and all
of that, right?
So even if you have a car.
Car itself as a complex data type, but it breaks down to like speed, it breaks down to real amount
or wheel count or whatever.
And in the end it's always like numbers or strings.
So integers, strings, floats and all of that primitive data types.
Anyway.
So let's see now how we can make use of our more complex data type person inside of our list box names
so that we can see the name property and the age property.
First of all, we need to create a list If we want to create a property or a field right here, we need
to make sure that our person class is set to public.
If not, we will not get access to it.
So the accessibility will throw an error.
So make sure that you set it to public.
If you want to create a field, which is what I will do now.
So I will create a property here right down prop hit tab, set the data type of that property to be
list of type person and I will set the name of this property to people.
Right.
So if you see an error with the accessibility here, as I said, it will come from the class be not
set to public.
Now, next up, I want to set the itemssource to be people.
Not a problem.
Why does it work?
As I explained already, it is an enumerable and a list is an enumerable.
So if we dig deeper into list with F 12, I just want to show you that you can see that it is using
the I list right here.
If we F12 in that again you can see that we have the enumerable here.
All righty.
So don't worry too much about that.
But like, I don't want to talk.
I want to show.
Great.
Now we got the ListBox and the Itemssource and the people here, so we set the Itemssource to be a list.
Now we need to create some initial values.
Therefore, I will remove that here.
Public list people, new list of type person, and then we will initialize it with some default values.
If we want to do that, we write down new person.
Then we open up the curly braces.
Now we can initialize the name with an equal sign, set it to Yannick comma separated.
We can set the next property, which would be age, set it to 30 and a comma.
And now we're good to go to add another person.
And another one.
It should be good to go, Mark.
Scott and Lucas right now.
Let's adjust the ages.
Looks good to me.
Okay, now let's start the application and let's see what happens.
And we should be able to see that we're using a complex data type here.
He basically just creates those items and writes down our complex data type name, right?
So here we got our person class.
It's just like our class dot two string.
This is what we will come up with in the end.
You need to come up with a so called item template for our list box where we can define what exactly
we want to display and what we want to bind and all of that.
So in this case, we want to go to our list box right here and we want to add an item template which
consists of a data template and then whatever we want to display.
So next up, we will adjust that.
But real quick, what we want to do now is adjust the name because this list box will no longer only
show names.
It will show people let's call it list box people.
And for sure, if you do that, copy it over, go to your code behind and adjust the name in line 39.
Let's say list box people, item source people.
Now, in that way it makes sense.
It's congruent.
Again, the name is matching the actual well data type, right?
That is just good programming behavior.
So in the next lesson, we'll get started with the item template where you will learn how you can get
the most out of the list box.