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  联系我,非常感谢。

  • 相关阅读:
    Python paramiko安装报错
    Python 函数返回值类型
    python 数据类型
    python — 模块(二)
    python — 模块(一)
    python 总结
    python 小知识3
    python 小知识3
    python 小知识2
    python — 计算机基础知识
  • 原文地址:https://www.cnblogs.com/lollipop/p/3061090.html
Copyright © 2011-2022 走看看