欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF 将子控件的属性绑定到父控件的属性中

程序员文章站 2022-06-08 17:14:48
...

其实就是在后台代码进行数据绑定

            TextBlock  _scaleTextBlock = new TextBlock();
            Binding binding = new Binding()
            {
                Path = new PropertyPath("Scale"),
                Source = this,
                StringFormat = "{0:P0}",
                Mode = BindingMode.TwoWay
            };
         
             _scaleTextBlock.SetBinding(TextBlock.TextProperty, binding);
             this.Children.Add(_scaleTextBlock);