An items control is used to customize list controls.
If you are creating an items control from scratch follow these steps.
I am declaring a class Person with two properties name and city in my project.
My main aim is to bind the objects of Person class to an items control and set their
|Project files||Person Class|
public class Person
An Itemscontrol includes four important elements.
Step1: Adding items to control
Add reference to your namespace. Create objects of Person class and add it to the Items property.
Step2: Setting the appearance of individual item.
Set the template for individual item. Here you have to set the DataTemplate property within ItemTemplate and bind the elements to the properties of objects created. If you do not bind you will get the data in Namespace.Class format.
Step3: Setting the template of control.
This step is optional. Setting the template means you are recreating the control.
You are adding and removing the parts of a control.Once the elements are added to set the appearance , do add a very important element called the ItemsPresenter.
ItemsPresenter like ContentPresenter in content controls makes your items visible .Your items won’t be visible if you set the template and forget to add ItemsPresenter.
You can even decide the layout of items in the panel by setting the ItemsPanelTemplate.It is again optional.
Here is the whole xaml code following the above steps with a pic below of my custom Itemscontrol.