在Phone7中去掉了listview控制項,就只有這個listbox控制項,不過這個控制項功能非常強大,完全可以實現listview的功能。 因為這個控制項也相當於一個容器,可以通過ListItem來組合多個控制項而得到不同功能的list。
Xaml:
<ListBox Grid.Row="1" Height="567" HorizontalAlignment="Left" Margin="12,53,0,0" Name="listBox1" VerticalAlignment="Top" Width="460">
<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}:動態綁定圖片資源。
//{Binding Name}:動態綁定text文字。
原始碼:
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;