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

推荐订阅源

月光博客
月光博客
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
MyScale Blog
MyScale Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
I
InfoQ
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security

博客园 - 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);
    }
}