Silverlight绑定到列表相关技巧

开发 开发工具
Silverlight绑定到列表可以通过一系列的代码编写来实现。在本文中,将会给出具体的代码编写过程,希望大家可以掌握这一技巧。

Silverlight中的数据绑定是一个非常重要的部分。它的灵活运用,使我们在开发过程中能够轻松自如的实现各种功能的需求。在这里我们就为大家介绍一种是用技巧,Silverlight绑定到列表的实现方法。#t#

下面再看一个Silverlight绑定到列表的简单例子,一般都会使用DataGrid或者ListBox来进行列表数据的显示。下面的示例我们显示一个文章列表:

  1. < Grid Background="#46461F"> 
  2. < Grid.RowDefinitions> 
  3. < RowDefinition Height="40">
  4. < /RowDefinition> 
  5. < RowDefinition Height="*">
  6. < /RowDefinition> 
  7. < /Grid.RowDefinitions> 
  8. < Grid.ColumnDefinitions> 
  9. < ColumnDefinition>
  10. < /ColumnDefinition> 
  11. < /Grid.ColumnDefinitions> 
  12. < Border Grid.Row="0" 
    Grid.Column="0" CornerRadius="15" 
  13. Width="240" Height="36" 
    Background="Orange" 
  14. Margin="20 0 0 0" Horizontal
    Alignment
    ="Left"> 
  15. < TextBlock Text="文章列表" 
    Foreground="White" 
  16. HorizontalAlignment="Left" 
    VerticalAlignment="Center" 
  17. Margin="20 0 0 0">< /TextBlock> 
  18. < /Border> 
  19. < ListBox x:Name="PostList" 
    Grid.Column="0" Grid.Row="1" 
  20. Margin="40 10 10 10" 
  21. HorizontalContentAlignment="Left" 
    VerticalContentAlignment="Bottom" 
  22. ItemsSource="{Binding Posts}"> 
  23. < /ListBox> 
  24. < /Grid> 

编写一个简单的Silverlight绑定到列表的业务类:

  1. public class Blog  
  2. {  
  3. public List< String> 
    Posts { get; set; }  

初始化集合数据并进行绑定

 

  1. private void UserControl_Loaded
    (object sender, RoutedEventArgs e)  
  2. {  
  3. Blog blog = new Blog();  
  4. blog.Posts = new List< String> 
  5. {  
  6. "一步一步学Silverlight 2系列
    (10):使用用户控件",  
  7. "一步一步学Silverlight 2系列
    (9):使用控件模板",  
  8. "一步一步学Silverlight 2系列
    (8):使用样式封装控件观感",  
  9. "一步一步学Silverlight 2系列
    (7):全屏模式支持"  
  10. };  
  11. PostList.DataContext = blog;  

Silverlight绑定到列表相关实现方法就为大家介绍到这里。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-10 16:35:08

PHP操作文章列表

2009-12-30 09:55:51

Silverlight

2010-01-04 14:49:30

Silverlight

2009-12-29 16:08:41

Silverlight

2009-12-30 18:18:32

Silverlight

2009-12-30 13:37:24

Silverlight

2009-12-31 10:21:53

Silverlight

2009-12-30 10:25:03

Silverlight

2009-12-31 16:44:53

Silverlight

2009-09-01 16:49:56

C#文件上传下载

2009-12-30 18:07:54

Silverlight

2010-09-28 14:06:43

Sql Server表

2009-12-16 14:33:21

Ruby哈希表

2009-12-30 09:38:37

Silverlight

2010-01-04 15:34:18

2021-06-23 14:21:06

PythonClassPython基础

2009-12-31 15:53:28

SilverLight

2009-12-31 13:33:35

Silverlight

2010-07-21 09:32:03

Linux多核

2009-12-30 13:30:16

Silverlight
点赞
收藏

51CTO技术栈公众号