我刚刚意识到我一直在强制绑定/依赖属性,但并没有真正理解这个概念。
下面是依赖属性:
public string Problem
{
get { return (string)GetValue(ProblemProperty); }
set { SetValue(ProblemProperty, value); }
}
public static readonly DependencyProperty ProblemProperty =
DependencyProperty.Register(
"Problem",
typeof(string),
typeof(TextBox));
XAML如下所示:
<TextBlock Text="{Binding Path=Problem}"/>
我在对象的构造函数中手动设置Problem
属性的值,但它不会相应地更新TextBlock
。有什么想法吗?我尝试了绑定中的Mode="OneWay"
和Mode="TwoWay"
,但仍然无法工作。
我以为这应该自动工作的?或者我基本上是在犯错?
谢谢