zoukankan      html  css  js  c++  java
  • WPF Binding的代码实现

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;


    namespace XamlTest
    {
        /// <summary>
        /// Interaction logic for Window7.xaml
        /// </summary>
        public partial class Window7 : Window
        {
            public Window7()
            {
                InitializeComponent();
                //Binding b = new Binding();
                //b.Source = s;
                //b.Path = new PropertyPath("Name");
                //BindingOperations.SetBinding(this.txtName, TextBox.TextProperty, b);


                //第二种写法
                this.txtName.SetBinding(TextBox.TextProperty, new Binding("Name") { Source = s });
            }
            private Student s=new Student();
            private void btn_Click_1(object sender, RoutedEventArgs e)
            {
                s.Name += "Name";
            }
        }

    }


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;


    namespace XamlTest
    {
        public class Student:INotifyPropertyChanged
        {
            private string name;


            public string Name
            {
                get { return name; }
                set 
                { 
                    name = value;
                    OnPropertyChanged("Name");
                }
            }


            public event PropertyChangedEventHandler PropertyChanged;


            public void OnPropertyChanged(string propertyName)
            {
                if (PropertyChanged!=null)
                {
                    PropertyChanged.Invoke(this,new PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }

  • 相关阅读:
    python's eithteenth day for me 面向对象——命名空间
    python's seventeenth day for me 面向对象
    python's sixteenth day for me 员工信息表
    python's fifteenth day for me 递归函数
    python's fourteenth day for me 内置函数
    用装饰器做一个登陆功能(进阶):
    装饰器 为多个函数加上认证功能(账号密码来源于文件),要求只要登陆成功一次,后续函数则无需登陆。
    python's thirteenth day for me 迭代器 生成器
    php函数
    php日期格式
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434630.html
Copyright © 2011-2022 走看看