| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1416 人关注过本帖
标题:如何使用依赖对象实现两个TextBox联动
只看楼主 加入收藏
hellenism
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2009-2-27
结帖率:76.47%
收藏
 问题点数:0 回复次数:2 
如何使用依赖对象实现两个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 编辑 ]
搜索更多相关主题的帖子: return 
2011-04-27 18:07
hellenism
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2009-2-27
收藏
得分:0 
请问为什么 textBox1和textBox2没有实现联动呢?
2011-04-27 18:17
雨夜星光
Rank: 4
等 级:业余侠客
帖 子:66
专家分:230
注 册:2009-11-25
收藏
得分:0 
不知楼主说的联动是什么样的联动?是一个txb中写的同时,另一个txb中也会随之显示吗?这样的话,直接可以用绑定的效果实现的啊。

C/C++交流群:65802335
2011-05-03 20:53
快速回复:如何使用依赖对象实现两个TextBox联动
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022423 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved