windows phone 之ListBox数据绑定

对于windows phone的ItemSource绑定,需要注意,绑定的数据源必须要声明get,否则绑定不生效

 1  <ListBox ItemsSource="{ Binding  Students }">
 2                 <ListBox.ItemTemplate>
 3                     <DataTemplate>
 4                         <StackPanel Orientation="Vertical">
 5                             <TextBlock Text="学号:" Foreground="Blue"></TextBlock>
 6                             <TextBlock Text="{Binding StuId}"></TextBlock>
 7                             <TextBlock Text="姓名:" Foreground="Blue"></TextBlock>
 8                             <TextBlock Text="{Binding Name}"></TextBlock>
 9                             <TextBlock Text="年龄:" Foreground="Blue"></TextBlock>
10                             <TextBlock Text="{Binding Age}"></TextBlock>
11                             <TextBlock Text="家庭住址:" Foreground="Blue"></TextBlock>
12                             <TextBlock Text="{Binding Address}"></TextBlock>
13                             <TextBlock Text="-----------------------"></TextBlock>
14                         </StackPanel>
15                     </DataTemplate>
16                 </ListBox.ItemTemplate>
17             </ListBox>
 1   public List<Student> _Students = null;
 2         public List<Student> Students { get { return _Students; } }//必须要有get访问器
 3 
 4         // 构造函数
 5         public MainPage()
 6         {
 7            
 8             if (_Students == null)
 9             {
10                 _Students = new List<Student>();
11                 _Students.Add(new Student() { StuId = "001", Name = "张一", Age = 12, Address = "杭州市滨江区江南大道1" });
12                 _Students.Add(new Student() { StuId = "002", Name = "张二", Age = 12, Address = "杭州市滨江区江南大道2" });
13                 _Students.Add(new Student() { StuId = "003", Name = "张三", Age = 12, Address = "杭州市滨江区江南大道3" });
14                 _Students.Add(new Student() { StuId = "004", Name = "张四", Age = 12, Address = "杭州市滨江区江南大道4" });
15                 _Students.Add(new Student() { StuId = "005", Name = "张五", Age = 12, Address = "杭州市滨江区江南大道5" });
16 
17             }
18             InitializeComponent();
19 
20         }
21 
22 
23         protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
24         {
25             DataContext = this;
26             base.OnNavigatedTo(e);
27         }
1  public class Student
2     {
3         public string StuId { get; set; }
4         public string Name { get; set; }
5         public int Age { get; set; }
6         public string Address { get; set; }
7 
8     }

 

转载于:https://www.cnblogs.com/lollipop/archive/2013/05/05/3061090.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值