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

推荐订阅源

GbyAI
GbyAI
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
小众软件
小众软件
博客园_首页
博客园 - 聂微东
罗磊的独立博客
Recent Announcements
Recent Announcements
U
Unit 42
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
D
DataBreaches.Net
Last Week in AI
Last Week in AI

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