开发者

How to make a simple table with names in Windows Phone 7?

I would like to have a simple table with small images and names so that when I click on a cell/item an开发者_如何学编程other view is displayed? how can I do that? I've got some experience with iphone development and .NET but I'm new to WP 7, thanks


You can use a ListBox to do this as follows:

<ListBox ItemsSource="{Binding Items}"
         SelectionChanged="OnListSelectionChanged">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <Image Source="{Binding ImageSource}" />
        <TextBlock Text="{Binding ItemName}" />
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

This will display a list or table with an image and some text in a row. Your view model needs to declare some sort of collection of Item objects (List<Items> if it is static or ObservableCollection<Items> if things can be added / removed). Each Item must have at least 2 public properties, ImageSource (string containing path to the image) & ItemName (string containing description).

In the OnListSelectionChanged handler do this

var item = (sender as ListBox).SelectedItem as Item;
// you can now access item.ItemName or item.ImageSource or other properties of Item

Data binding is a vast topic, and you should learn more about it before attempting to write an app. Here's an MSDN article that deals with the basics.

Specifically for Windows Phone development, I recommend you download Charles Petzold's free book and read that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜