一起学Windows Phone7开发( ListBox控件)

在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;

 

 

原文链接:http://www.52zixue.com/zhanzhang/silverlight/2012/0326/8877_3.html

转载于:https://www.cnblogs.com/ouyating/archive/2012/05/23/2515019.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值