开始写wpf笔记,都为小示例
1.创建一个类
{
public class Person
{
private string _nameProperty = "Joe";
public Person() { }
public string Name
{
get
{
return _nameProperty;
}
set
{
this._nameProperty = value;
}
}
}
}
2.在xaml中声明对象(src为注册对象,类似asp.net控件的<asp:xxx的asp一样
3.实行绑定
使用Binding标签对象绑定
<TextBox.Text>
<Binding Source="{StaticResource xxx}" Path="Name"/>
</TextBox.Text>
</TextBox>
4.使用ObjectDataProvider对象作为数据源对象(注意ObjectType属性为扩展对象类型为scr:Person,如同asp.net控件
上面代码改为
5.更改绑定对象
<TextBox.Text>
<Binding Source="{StaticResource myDataSource}" Path="Name"/>
</TextBox.Text>
</TextBox>
6.效果
完