예제 #1
0
        /// <summary>
        /// 后台C#绑定数据
        /// </summary>
        public void binding(Student s)
        {
            //创建一个binding实例
            Binding b1 = new Binding
            {
                //指定绑定值来源
                Path = new PropertyPath(nameof(Student.ID))
            };

            //绑定数据到控件
            T1.SetBinding(TextBlock.TextProperty, b1);

            Binding b2 = new Binding
            {
                Path = new PropertyPath(nameof(Student.StuName))
            };

            T2.SetBinding(TextBlock.TextProperty, b2);

            Binding b3 = new Binding
            {
                Path = new PropertyPath(nameof(Student.Age))
            };

            T3.SetBinding(TextBlock.TextProperty, b3);

            panel.DataContext = s;//绑定到父控件上
        }