0
我想将我的WFP应用程序中的TextBox.Text
属性绑定到EF实体对象的属性。将WPF文本框绑定到实体对象
这里是实体对象的初始化:
public static Question CurrentQuestion = new Question
{
Description = "How old are you?"
};
这里是功能,数据绑定文本框:“你多大了”
private void BindQuestionControls()
{
Binding b = new Binding();
b.Source = CurrentQuestion;
b.Mode = BindingMode.TwoWay;
b.Path = new PropertyPath("Description");
textBoxQuestion.SetBinding(TextBlock.TextProperty, b);
}
我希望当应用程序启动,然后textBoxQuestion将显示但它是空的,可能最好是在声明中设置绑定,请建议如何做到这一点。谢谢。
不知道,如果你犯了一个错字,但在设置装订线,你必须使用TextBox.TextProperty不TextBlock.TextProperty。 然后这段代码在我的机器上正常工作。 – paiden
哦,是的,谢谢你。 – igorGIS