WPF 中的绑定方式

1、元素间的绑定

xaml方式

<Slider Name="slider1" Value="20"/>
        <TextBlock TextWrapping="Wrap" FontSize="20" Text="{Binding ElementName=slider1,Path=Value,Mode=TwoWay}"/>

 

代码方式

Student stu = new Student();
Binding binding = new Binding();
binding.Source = stu;
binding.Path = new PropertyPath("Name");
BindingOperations.SetBinding(this.textBoxName, TextBox.TextProperty, binding);

2、绑定到非元素对象

source 方式

绑定到静态的资源或者静态字段

relativesource 方式

绑定自己或者父元素

datacontext方式

绑定数据源

posted @ 2016-04-06 22:20  小灬琦哥  阅读(390)  评论(0编辑  收藏  举报