Only the listbox control is removed from the listview control in Phone7. However, this control is very powerful and can fully implement the listview function. This control is equivalent to a container. You can use ListItem to combine multiple controls to obtain a list of different functions.
Xaml:
<ListBox Grid. row = "1" Height = "567" HorizontalAlignment = "Left" Margin = "460," Name = "listBox1" VerticalAlignment = "Top" Width = "">
<ListBox. ItemTemplate>
<DataTemplate>
<StackPanel Orientation = "Horizontal">
<Image Source = "{Binding ImgSource}" Width = "130" Height = "130"/>
<TextBlock Text = "{Binding Name}" Foreground = "Yellow" FontSize = "25"/>
</StackPanel>
</DataTemplate>
</ListBox. ItemTemplate>
</ListBox>
// {Binding ImgSource}: dynamically binds image resources.
// {Binding Name}: dynamically binds text.
Source code:
ImageList item1 = new ImageList ();
Item1.ImgSource = new BitmapImage (new Uri ("Images/Chrysanthemum.jpg", UriKind. Relative ));
Item1.Name = "Chrysanthemum.jpg ";
List. Add (item1 );
ImageList item2 = new ImageList ();
Item2.ImgSource = new BitmapImage (new Uri ("Images/Desert.jpg", UriKind. Relative ));
Item2.Name = "Desert.jpg ";
List. Add (item2 );
ImageList item3 = new ImageList ();
Item3.ImgSource = new BitmapImage (new Uri ("Images/Hydrangeas.jpg", UriKind. Relative ));
Item3.Name = "Hydrangeas.jpg ";
List. Add (item3 );
ListBox1.ItemsSource = list;
<ListBox Height = "605" HorizontalAlignment = "Left" Margin = "460," Name = "listBox1" verticalignment = "Top" Width = "">
<ListBox. ItemTemplate>
<DataTemplate>
<StackPanel Orientation = "Horizontal">
<Button Content = "{Binding ColorName}" Click = "Button_Click"/>
<TextBlock x: Name = "tb" Text = "{Binding ColorName}" FontSize = "35"/>
</StackPanel>
</DataTemplate>
</ListBox. ItemTemplate>
</ListBox>
Void MainPage_Loaded (object sender, RoutedEventArgs e)
{
ColorItem color = new ColorItem ();
Color. ColorName = "Red ";
Color. ColorValue = Colors. Red;
List. Add (color );
ColorItem color1 = new ColorItem ();
Color1.ColorName = "Green ";
Color1.ColorValue = Colors. Green;
List. Add (color1 );
ColorItem color2 = new ColorItem ();
Color2.ColorName = "Blue ";
Color2.ColorValue = Colors. Blue;
List. Add (color2 );
This. listBox1.ItemsSource = list;
}
Private void Button_Click (object sender, RoutedEventArgs e)
{
String button = (sender as Button). Content as string;
Int index = 0;
String color = string. Empty;
For (index = 0; index <list. Count; index ++)
{
If (button = list [index]. ColorName)
{
Color = list [index]. ColorName;
Break;
}
}
ListBoxItem lbi = this. listBox1.ItemContainerGenerator. ContainerFromIndex (index) as ListBoxItem;
TextBlock tb = FindFirstVisualChild <TextBlock> (lbi, "tb ");
Tb. Foreground = new SolidColorBrush (list [index]. ColorValue );
}