‫Welcome back.
‫In this video, we're going to cover the combo box and you can see one here.
‫And it has the data source of all the different colors that are available to us.
‫So let's say we want to use pale violet red as we have already.
‫We can simply select that.
‫And as you can see, our combo box has selected this color and it even has this whole beautiful text
‫about what this color is called like.
‫Okay, so let's go ahead and create a new project to get started and I'm going to call that one WP F
‫ten C combo box and you can call it however you like.
‫But what we will need in here is an example.
‫We are going to create a stack panel first.
‫So instead of grid, I want to use Stack panel and I'm going to make XAML a little bigger here because
‫the design is nice and all, but it's always good to see what you're coding.
‫And in here I will create something called a combo box and that's pretty much it.
‫There is my combo box.
‫I can give it a name, so I'm going to call it name is equal to combo box colors.
‫And now that combo box needs a combo box item template, something that we have seen in the last video
‫where we used the list box.
‫So we have this combo box item template in here.
‫We need to have a data template because otherwise, as you can see, it's complaining.
‫And now as soon as we have this data template, it's all good and I'm going to get rid of the additional
‫lines that I have created here.
‫So in here I want to have a Stack panel because I want to stack everything up in there and it should
‫be oriented horizontally.
‫Now, the STACK panel should contain a rectangle.
‫By the way, the STACK panel is going to be what's inside of our combo box, and it should contain a
‫rectangle, which I'm going to fill with a color.
‫So I'm going to fill it with binding name and it should have a width of, let's say 32 pixels and a
‫height of also 32 pixels.
‫And then I want to add a margin of let's say five pixels towards all directions for that rectangle.
‫And now there should be a text block also saying the name.
‫So this text block should have a text called binding name.
‫So we're going to bind the name property.
‫So we will need to create a name property.
‫And also I want to add a font size of 32 to my text block.
‫All right.
‫So that's pretty much it.
‫That's our whole code that we need in XAML.
‫And now we can go ahead and run or create a code that we will need in code behind, because what we
‫all need is definitely this name property.
‫So let's go in the code behind and in here.
‫I'm going to go ahead and I'm going to simply access my combo box colors, which is our main window
‫dot combo box colors.
‫So this one here, I call this combo box like that.
‫I call the combo box colors.
‫And now what I will do is I will set the item source.
‫So items source is going to be our colors dot get property and we cannot use it that way.
‫So we'll need to send it type of colors, dot get properties.
‫So we'll get all of the colors that are available in.
‫This class your system that windows that media colors and in there is a method called get properties
‫and it will give us back all the colors.
‫So that's pretty much it.
‫We set the item source to this colors property.
‫We could have of course, used a list of elements in here of objects that we want to show in here.
‫But having this beautiful approach here is going to super simple.
‫As you can see, we have just one line with so many different values that we can choose from.
‫So we simply have this combo box which contains all of those colors and we can use this chocolate color
‫or we could use a dark slate, gray and so forth.
‫So as you can see, you can set the item source to a pretty cool list that is internally available.
‫Or you can create your own item source, which could be of course, some data from a database, or it
‫could be a list that you create yourself.