In the last step, you added the C1TileListBox control to the application. In this step, you will add code to bind the control to data.
Complete the following steps to add data to the control programmatically:
1. Right-click the page and select View Code to open the Code Editor.
2. Add the following imports statements to the top of the page:
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Xml.Linq
Imports System.Net
Imports C1.Phone
•C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using C1.Phone;
3. Add the following code inside the initial event handler within the MainPage class:
DataContext = Enumerable.Range(0, 100).[Select](Function(i) New Item() With {.Title = i.ToString()})
•C#
DataContext = Enumerable.Range(0, 100).Select(i => new Item { Title = i.ToString() });
4. Add the following code below the initial event handler butwithin the MainPage class:
#Region "** public properties"
Public Property Orientation() As Orientation
Get
Return tileListBox.Orientation
End Get
Set(value As Orientation)
tileListBox.Orientation = value
End Set
End Property
Public Property ItemWidth() As Double
Get
Return tileListBox.ItemWidth
End Get
Set(value As Double)
tileListBox.ItemWidth = value
End Set
End Property
Public Property ItemHeight() As Double
Get
Return tileListBox.ItemHeight
End Get
Set(value As Double)
tileListBox.ItemHeight = value
End Set
End Property
Public Property ZoomMode() As ZoomMode
Get
Return tileListBox.ZoomMode
End Get
Set(value As ZoomMode)
tileListBox.ZoomMode = value
End Set
End Property
#End Region
•C#
#region ** public properties
public Orientation Orientation
{
get
{
return tileListBox.Orientation;
}
set
{
tileListBox.Orientation = value;
}
}
public double ItemWidth
{
get
{
return tileListBox.ItemWidth;
}
set
{
tileListBox.ItemWidth = value;
}
}
public double ItemHeight
{
get
{
return tileListBox.ItemHeight;
}
set
{
tileListBox.ItemHeight = value;
}
}
public ZoomMode ZoomMode
{
get
{
return tileListBox.ZoomMode;
}
set
{
tileListBox.ZoomMode = value;
}
}
#endregion
The code above binds the C1TileListBox to a list of numbers.
5. Add the following code just below the MainPage class:
Public Class Item
Public Property Title() As String
Get
Return m_Title
End Get
Set(value As String)
m_Title = Value
End Set
End Property
Private m_Title As String
Public Property Thumbnail() As String
Get
Return m_Thumbnail
End Get
Set(value As String)
m_Thumbnail = Value
End Set
End Property
Private m_Thumbnail As String
End Class
•C#
public class Item
{
public string Title { get; set; }
public string Thumbnail { get; set; }
}
What You've Accomplished
You have successfully added data to C1TileTileListBox. In the next step, Step 3 of 3: Running the TileListBox Application, you'll examine the TileListBox for Windows Phone features.