This article demonstrates how to use Item Control in Silverlight
Windows Phone 7. Item control and its derivatives show the collection of
records. Using selector user can select one or more records from the
collection.
Getting Started
Creating a Windows Phone Application:
- Open Visual Studio 2010.
- Go to File => New => Project
- Select Silverlight for Windows Phone from the
Installed templates and choose Windows Phone Application
- Enter the Name and choose the location.
Click OK
First of all drag and drop a ItemControl
,ListBox and a ComboBox.
MainPage.xaml
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ItemsControl Name="StatesItemControl" Grid.Column="0"></ItemsControl>
<ListBox Name="StatesListBox" Grid.Column="1"></ListBox>
<ComboBox Name="StatesComboBox" Grid.Column="2" VerticalAlignment="Top" Foreground="Black"
</ComboBox>
</Grid>
// Constructor
public
MainPage()
{
InitializeComponent();
FillStates(StatesItemControl);
FillStates(StatesListBox);
FillStates(StatesComboBox);
}
{
string[]
states = { "Alabama", "Alaska", "Arizona",
"Arkansas", "California",
"Colorado", "Connecticut","Delaware","District
of Columbia",
"Florida","Georgia","Hawaii","Idaho",
"Illinois",
"Indiana","Iowa","Kansas", "Kentucky",
"Louisiana",
"Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota",
"Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada",
"New Hampshire", "New Jersey", "New
Mexico", "New York",
"North Carolina", "North Dakota", "Ohio
Oklahoma", "Oregon",
"Pennsylvania", "Rhode
Island", "South Carolina",
"South Dakota", "Tennessee",
"Texas", "Utah",
"Vermont",
"Virginia", "Washington",
"West Virginia","Wisconsin",
"Wyoming", "Puerto
Rico", "Virgin Island",
"Northern Mariana Islands", "Guam", "American
Samoa", "Palau"};
foreach
(string state in
states)
items.Items.Add(state);
}
Image
1.
As you
can see there is no scroll in Item Control if you want to put scroll in Item
Control then put in ScrollViewer.
Image
2.
When
you touch on combo box then states list should be display like this.
Image
3.

Fennie LauPosted May 27, 2012, 9:09 AM
May I ask why my visual studio 2010 tool box do not have combo box? But I try the demo you post at here,the combo box is available. But if I create a new project, it is not works. May I ask how to solve this?