惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
月光博客
月光博客
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
IT之家
IT之家
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
爱范儿
爱范儿

博客园 - zyip

超越2028:我们这一代,是末代普通程序员 中国生成式AI民用开荒史:2022–2023 icon资源 python几类安装方法 pyautogui 深入理解 CSS 中的 BFC React17 , CRA项目添加Access-Control-Allow-Origin header wpf mvvm(prism) wpf 打包成单文件 vite 读取router mysql ensp run Python asyncio code in a Jupyter notebook 实现两个socket server 黑苹果 Sublime Text4 4143版本激活 comfyUI相关 windows命令行批量给文件名加前缀 unable to resolve dependency tree
wpf data binding
zyip · 2023-12-09 · via 博客园 - zyip
    public partial class Window2 : Window
    {   
        public Person vmPerosn = new Person();
        public Window2()
        {
            InitializeComponent();

            vmPerosn.Name = "Jack Zhao";
            vmPerosn.Phone = "13666666666";
            vmPerosn.idNo = "110110110110110110";
            //tb1.DataContext = vmPerosn;
            this.DataContext = vmPerosn;
            //< TextBox Name = "tb1" Grid.Column = "3"  Text = "{Binding Path=Name}"  TextWrapping = "Wrap" VerticalContentAlignment = "Center" HorizontalContentAlignment = "Stretch" />

            Binding myBinding = new Binding();
            myBinding.Source = vmPerosn;
            myBinding.Path = new PropertyPath("Phone");
            myBinding.Mode = BindingMode.TwoWay;
            myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(tb2, TextBox.TextProperty, myBinding);
        }
    }

 two way binding

public partial class Window2 : Window
{   
    public Person vmPerosn = new Person();
    public Window2()
    {
        InitializeComponent();

        vmPerosn.Name = "Jack Zhao";
        vmPerosn.Phone = "13666666666";
        vmPerosn.idNo = "110110110110110110";
        //tb1.DataContext = vmPerosn;
        this.DataContext = vmPerosn;
        //< TextBox Name = "tb1" Grid.Column = "3"  Text = "{Binding Path=Name}"  TextWrapping = "Wrap" VerticalContentAlignment = "Center" HorizontalContentAlignment = "Stretch" />
        // < TextBox Name = "tb1" Grid.Column = "3"  Text = "{Binding Path=Name, Mode = TwoWay,  UpdateSourceTrigger=PropertyChanged}"  TextWrapping = "Wrap" VerticalContentAlignment = "Center" HorizontalContentAlignment = "Stretch" TextChanged = "tb1_TextChanged" />

        Binding myBinding = new Binding();
        myBinding.Source = vmPerosn;
        myBinding.Path = new PropertyPath("Phone");
        myBinding.Mode = BindingMode.TwoWay;
        myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        BindingOperations.SetBinding(tb2, TextBox.TextProperty, myBinding);
    }

    private void tb1_TextChanged(object sender, TextChangedEventArgs e)
    {
        MessageBox.Show(vmPerosn.Name);
    }

    private void tb2_TextChanged(object sender, TextChangedEventArgs e)
    {
        MessageBox.Show(vmPerosn.Phone);
    }
}