一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net silverlight中使用listbox展示数据

时间:2022-06-25 04:02:17 编辑:袖梨 来源:一聚教程网

通过后台绑定的方式绑定listbox的数据,包括模板样式;效果如下:
前台页面:
 代码如下 复制代码

       
  
   
    
     
    

   

  

 

       
           
           
           
             
           
           
              
           
           
               
                   
                   
                       
                           
                               
                               
                           
                      
                               
                               
                               
                               
                           
                       
                   
               
           
       
   
 
 
app.xaml页面里有模板样式:
 代码如下 复制代码

       
       
       
       
       
       
       
 
后台页面:
 代码如下 复制代码
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var Persons = new List();
            for (int i = 0; i < 10; i++)
   {
                Persons.Add(new person {Image="/Image/user00"+i+".png", Title = "关注的人最新更新:" + i.ToString(), Time = "创建时间:" + DateTime.Now.ToShortDateString().ToString() ,Author="作者:"+i.ToString()});
   }
            listBox1.ItemsSource = Persons;
        }
        public class person
        {
            private string image;
            public string Image
            {
                get { return image; }
                set { image = value; }
            }
            private string title;
            public string Title
            {
                get { return title; }
                set { title = value; }
            }
            private string time;
            public string Time
            {
                get { return time; }
                set { time = value; }
            }
            private string author;
            public string Author
            {
                get { return author; }
                set { author = value; }
            }
        }
    }

热门栏目