测试相关类
public class HostTest
{
public string Value{get; set;}
public string Value1 {get ;set ;}
}
public class Test
{
private string _value = null;
public string Value
{
get { return _value; }
set
{
_value = value;
}
}
private string _value1 = null;
public string Value1
{
get { return _value1; }
set
{
_value1 = value;
}
}
}
实现效果是将一个HostTest 对象的两个属性绑定到Test的两个属性上,然后实现HostTest对应的属性改变,两个Test 对象的属性也自动修改,反之亦然,实现代码如下:
namespace BindingDemo
{
class Program
{
static void Main(string[] args)
{
var host = new HostTest();
var test = new Test();
var test1 = new Test();
host.AddBinding("Value", new Binding(test, "Value"));
host.AddBinding("Value1", new Binding(tes