文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Data Binding(1)

Data Binding(1)

时间:2010-12-14  来源:小楼①夜听春雨

1.

 <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Name="myText" Height="50" Foreground="LightBlue" Text="{Binding}" Margin="57,125,65,125"></TextBlock>
  </Grid>

2.

public class Employee
    {
        public String Name { set; get; }
        public DateTime BirthDay { set; get; }
        public Byte Gender { set; get; }
        public override string ToString()
        {
           return String.Format("Name:{0}, Birth of Day :{1}, Gender:{2}",Name, BirthDay.ToLongDateString(), Gender == 1? "Male":"Female");
        }
    }

3.

public partial class MainPage : UserControl
    {
        public Employee e = new Employee() { BirthDay = new DateTime(1984, 06, 28), Gender = 1, Name = "Mo.Li" };
        public MainPage()
        {
            InitializeComponent();
            this.myText.DataContext = e;//相应控件的DataContext 引用CLR对象
        }
    }

binding 到这个对象了, 很显然textblock 默认会调用ToString方法,开始so easy !

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载