UI元素的基类FramworkElement封装的SetBinding函数
<Window.Resources>
<sys:String x:Key="sd">
dasdsad
</sys:String>
</Window.Resources>
//这是数据资源 需要导入
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<TextBox x:Name="txt1" Background="#FFFF4545" />
<TextBlock x:Name="txt2" Text="{Binding Path=Text, ElementName=txt1}" />
<TextBlock x:Name="txt3" Text="{Binding .,Source= {StaticResource ResourceKey = sd}}"/>
//这是xaml 里面的代码
** txt3.SetBinding(***TextBlock.BackgroundProperty***, new Binding() { Path=new PropertyPath("Text"), Source = txt1});
**
** txt3.SetBinding(TextBlock.BackgroundProperty, new Binding("Text") { Source = txt1});
**
//把txt3的背景颜色(TextBlock.BackgroundProperty)绑定到txt1的Text(Path=new PropertyPath("Text"))属性上