WPF绑定到类中的属性

时间:2013-01-21 19:21:34

标签: wpf windows-phone-7 xaml

我正在尝试将文本框绑定到属性。

我想绑定到文本框的属性是在一个单独的类中:

public void errorText {get;set;}

在我的主页中,我已将数据上下文设置为errorText属性所在的类的实例,以便现在我的主页知道具有该属性的类:

this.Datacontext = instance;

现在在我的xaml中我将属性绑定到文本框:

 <TextBlock Height="121" HorizontalAlignment="Left" Margin="100,613,0,0" Name="TextBlockForErrorsMainPage" Text="{Binding errorText}" VerticalAlignment="Top" Width="285" Foreground="#FFEF1212" TextWrapping="Wrap" />

当我运行应用程序时,我没有任何快乐......对此有任何帮助吗?

感谢。

1 个答案:

答案 0 :(得分:0)

您将返回无效

public string errorText {get;set;}

并且可能还需要实施iNotifyPropertyChanged。

如果在Initialize()之前设置该值,则UI将看到该值。