SilverIight数据绑定实例

2016-09-21 11:29:11来源:cnblogs.com作者:罗曼蒂克'人点击

 

前台Code

<DataGrid Name="DataGrid1" AutoGenerateColumns="False" IsReadOnly="True" Width="550">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="100"/>
<DataGridTextColumn Header="Age" Binding="{Binding Age}" Width="100"/>
<DataGridTextColumn Header="Address" Binding="{Binding Address}" Width="100"/>
<DataGridTextColumn Header="Date" Binding="{Binding Date}" Width="200"/>
</DataGrid.Columns>
</DataGrid>

 

 

后台

public class Person
{
public String Name { get; set; }
public int Age { get; set; }
public String Address { get; set; }
public DateTime Date { get; set; }
}
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var persons = new List<Person>();
for (var i = 0; i < 5; i++)
{
persons.Add(new Person { Name = "Person " + i.ToString(), Age = 20 + i, Address = "Address", Date=DateTime.Now });
}
DataGrid1.ItemsSource = persons;
}
}

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台