你的位置:首页 > ASP.net教程

[ASP.net教程]silverlight简单数据绑定


.cs类

  public class Person  {     public String Name { get; set; }     public int Age { get; set; }         public String Address { get; set; }     } 

 

.xaml.cs

    void LayoutRoot_Loaded(object sender,RoutedEventArgs e)    {      Person person = new Person()      {       Name="Terry",       Age=20,       Address="Beijing"      };      this.LayoutRoot.DataContext = person;    }     

.xaml

 <Grid x:Name="LayoutRoot" Background="white" Loaded="LayoutRoot_Loaded">    <StackPanel>    <TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Name}"/>    <TextBlock Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Age}"/>    <TextBlock Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding Address}"/>    </StackPanel>  </Grid>