zoukankan      html  css  js  c++  java
  • 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     }


    作者:ゞ修ζ止符℡_R
    出处:http://www.cnblogs.com/lollipop/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过394406480@qq.com  联系我,非常感谢。

  • 相关阅读:
    [独孤九剑]Oracle知识点梳理(五)数据库常用对象之Table、View
    [独孤九剑]Oracle知识点梳理(四)SQL语句之DML和DDL
    [独孤九剑]Oracle知识点梳理(三)导入、导出
    [独孤九剑]Oracle知识点梳理(二)数据库的连接
    [独孤九剑]Oracle知识点梳理(一)表空间、用户
    [独孤九剑]Oracle知识点梳理(零)目录
    jmeter安装
    MongoDB 用Robomong可视化工具操作的 一些简单语句
    限制输入字数JS
    我们来谈谈最近最热门的微信小程序
  • 原文地址:https://www.cnblogs.com/lollipop/p/3061090.html
Copyright © 2011-2022 走看看