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

推荐订阅源

量子位
Recent Announcements
Recent Announcements
D
Docker
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC
B
Blog
博客园_首页
罗磊的独立博客
D
DataBreaches.Net
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence

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