[英]WPF TextBlock not updating
I have a standard texblock bound to a property in my viewmodel 我的视图模型中有一个绑定到属性的标准texblock
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding MyErrorMessage, Mode=Default,UpdateSourceTrigger=PropertyChanged}" Foreground="Red"></TextBlock>
The property 物业
private string _errorMessage;
public string MyErrorMessage
{
get { return _errorMessage; }
set
{
_errorMessage = value;
this.RaisePropertyChanged(this.MyErrorMessage);
}
}
I do a standard 我做一个标准
this.MyErrorMessage = "Login failed";
But the textblock is not updating. 但是文本块没有更新。 I can see the the setter and getter being called correctly, but still the textblock is not updating. 我可以看到setter和getter被正确调用,但文本块仍未更新。 Am i missing something fundamental? 我缺少基本的东西吗?
The property that is raised should have the string "MyErrorMessage" and NOT the value of the property. 引发的属性应具有字符串“ MyErrorMessage”,而不是属性的值。 ie 即
this.RaizePropertyChanged( "MyErrorMessage" )
If you fix this (and everything else is also set correct), you'll be fine. 如果您解决了这个问题(其他所有设置都正确),也没问题。
Side comments: There is no need for Mode=Default (as the name suggest, it is the default), and UpdateSourceTrigger=PropertyChanged (also the default, and doesn't make the code more readable). 旁注:不需要Mode = Default(顾名思义,它是默认值)和UpdateSourceTrigger = PropertyChanged(也是默认值,并且不会使代码更具可读性)。
RaisePropertyChanged takes a string http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx RaisePropertyChanged采用字符串http://msdn.microsoft.com/zh-cn/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx
So just change the call to 因此,只需将呼叫更改为
this.RaisePropertyChanged("MyErrorMessage");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.