如何使用依赖对象实现两个TextBox联动
程序代码:
public class Student : DependencyObject { public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Student)); public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } public BindingExpressionBase SetBinding(DependencyProperty dp, BindingBase binding) { return BindingOperations.SetBinding(this, dp, binding); } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Student stu = new Student(); stu.SetBinding(Student.NameProperty, new Binding("Text") { Source = this.textBox1}); this.textBox2.SetBinding(TextBox.TextProperty, new Binding("Name") { Source = stu}); }
请问textBox1与textBox2为什么没有实现联动呢?
[ 本帖最后由 hellenism 于 2011-4-27 18:18 编辑 ]