Telerik UI for Windows Phone by Progress

RadLoopingList uses the LoopingListDataSource class to generate data visualization and is virtualized. Items are created through an event only when needed. The event is called ItemNeeded.

Create and Fill a LoopingListDataSource

LoopingListDataSource is used together with the LoopingListDataItem class. Here is an example that fills the data source with the days of the week.

CopyC#
LoopingListDataSource src = new LoopingListDataSource(DateTimeFormatInfo.CurrentInfo.DayNames.Length);
IEnumerator dayEnumerator = DateTimeFormatInfo.CurrentInfo.DayNames.GetEnumerator();
src.ItemNeeded + = (sender, args) =>
{
if (dayEnumerator.MoveNext())
{
args.Item = new LoopingListDataItem(dayEnumerator.Current.ToString());
}
};

LoopingListDataSource is fully virtualized which is why data items are created in the ItemNeeded event handler. A data item is created only if it is going to be visualized.

The basic LoopingListDataItem supports only a text property. In order to add more properties users need to inherit from LoopingListDataItem and add the necessary information.

Then they can simply create an instance of their custom data item in the ItemNeeded event handler.

If the view port of the looping list is not big enough to display all of the data, which is almost always the case, users need to subscribe to the ItemUpdated event. ItemUpdated is called whenever the looping list needs to display new data, that is, data that is not visible at the moment, but that will be visualized shortly. For example when the looping list scrolls the items from the inertia caused by a user flick, the ItemUpdated event will be fired for items that will be visualized next. The arguments in the event handler provide the data item that has to be visualized and an index that corresponds to the real data record in the original data source. Users are expected to update the data item with the real data from their own data source. A code snippet will best illustrate this:

CopyC#
src.ItemUpdated + = (sender, args) =>
{
args.Item.Text = DateTimeFormatInfo.CurrentInfo.DayNames[args.Index].ToString();
};

Set LoopingListDataItem Text

By default the value displayed for the item will be the result from its ToString() method. The displayed value can be changed either in the constructor of the LoopingListDataItem, like the example above, or through its Text property. Here is an example using a simple class Employee. The LoopingListDataItem object will use the Name property as a display value.

CopyC#
public class Employee
{
public int Age
{
get;
set;
}

public string Name
{
get;
set;
}
}
CopyC#
LoopingListDataSource employees = new LoopingListDataSource(1);
Employee employee = new Employee()
{
Age = 22,
Name = "John Doe"
};
employees.ItemNeeded += (sender, args) =>
{
LoopingListDataItem dataItem = new LoopingListDataItem();
dataItem.Text = employee.Name;
args.Item = dataItem;
};