码迷,mamicode.com
首页 > 其他好文 > 详细

BInd绑定

时间:2014-07-29 13:44:58      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   color   文件   io   art   cti   代码   ar   

用通俗的代码解决

首先创建一个class类

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace WpfMvvm.ViewModels

{  

   class student

    {

        private string name;

        public string Name   

      {  

           get { return name; }             set { name = value; }   

      }

    }

}

引用空间system.ComponentModel,添加端口

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ComponentModel;

namespace WpfMvvm.ViewModels

{    

class student:INotifyPropertyChanged

    {

        private string name;

        public string Name  

       {         

    get { return name; }  

           set {            

     name = value;           

      if (PropertyChanged != null)       

          {    

                 this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Name"));

                }         

    }   

      }

        public event PropertyChangedEventHandler PropertyChanged;  

   }

}

添加一个xmal文件,student.xmal

   /// <summary>

    /// Student.xaml 的交互逻辑  

   /// </summary>   

  public partial class Student : Window   

  {  

       student stu;    

     public Student()      

   {      

       stu = new student();       

      InitializeComponent();      

       Binding bind = new Binding();     

        bind.Source = stu;      

       bind.Path = new PropertyPath("Name");    

         BindingOperations.SetBinding(this.textBox1,TextBox.TextProperty, bind);           

        }

        private void button1_Click(object sender, RoutedEventArgs e)    

     {        

     stu.Name += "name";    

     }    

}

}

 

有种简单的方法是用

  this.textBox1.SetBinding(TextBox.TextProperty,new Binding("Name"){Source=stu=new student()});

BInd绑定,布布扣,bubuko.com

BInd绑定

标签:style   color   文件   io   art   cti   代码   ar   

原文地址:http://www.cnblogs.com/cainiaojinjie/p/3875066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!