wpf学习笔记-简单绑定
2008-05-31 11:20 Clingingboy 阅读(1256) 评论(0) 编辑 收藏 举报
开始写wpf笔记,都为小示例
1.创建一个类
2.在xaml中声明对象(src为注册对象,类似asp.net控件的<asp:xxx的asp一样
3.实行绑定
使用Binding标签对象绑定
4.使用ObjectDataProvider对象作为数据源对象(注意ObjectType属性为扩展对象类型为scr:Person,如同asp.net控件
上面代码改为
5.更改绑定对象
6.效果
完
1.创建一个类
namespace SimpleBinding
{
public class Person
{
private string _nameProperty = "Joe";
public Person() { }
public string Name
{
get
{
return _nameProperty;
}
set
{
this._nameProperty = value;
}
}
}
}
{
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一样
<src:Person Name="aaaa" x:Key="xxx" ></src:Person>
3.实行绑定
使用Binding标签对象绑定
<TextBox Width="100" Height="25">
<TextBox.Text>
<Binding Source="{StaticResource xxx}" Path="Name"/>
</TextBox.Text>
</TextBox>
<TextBox.Text>
<Binding Source="{StaticResource xxx}" Path="Name"/>
</TextBox.Text>
</TextBox>
4.使用ObjectDataProvider对象作为数据源对象(注意ObjectType属性为扩展对象类型为scr:Person,如同asp.net控件
上面代码改为
<ObjectDataProvider x:Key="myDataSource" ObjectType="{x:Type src:Person}" IsAsynchronous="True" />
5.更改绑定对象
<TextBox Width="100" Height="25">
<TextBox.Text>
<Binding Source="{StaticResource myDataSource}" Path="Name"/>
</TextBox.Text>
</TextBox>
<TextBox.Text>
<Binding Source="{StaticResource myDataSource}" Path="Name"/>
</TextBox.Text>
</TextBox>
6.效果
完