[英]Binding text to my textblock isn't working
Here's the xaml: 这是xaml:
<TextBlock Text="{Binding Errors}" Grid.Row="3" Foreground="Red"/>
Here's the ViewModel code: 这是ViewModel代码:
private string _errors = "";
public string Errors
{
get { return this._errors; }
set
{
if(_errors != value)
{
_errors = value;
RaisePropertyChanged(() => Errors);
}
}
}
and then in some function I change the _errors
variable 然后在某些函数中我更改了
_errors
变量
_errors = "Compiler Errors :\r\n";
But nothing happens in the TextBlock. 但TextBlock中没有任何反应。 What am I doing wrong?
我究竟做错了什么?
You are setting _errors
variable directly - so no RaisePropertyChanged
fired. 您正在直接设置
_errors
变量 - 因此没有触发RaisePropertyChanged
。 Try to set value by 尝试设置值
Errors = = "Compiler Errors :\r\n";
private string _errors = "";
public string Errors
{
get { return this._errors; }
set
{
if(_errors != value)
{
_errors = value;
RaisePropertyChanged("Errors");
}
}
}
set it like this : 像这样设置:
Errors = "..."
I don't know how works the method RaisePropertyChanged, but if the lambda expression ()=>Errors is executed it will return the string contained in _errors and not the name of the property that changed ? 我不知道RaisePropertyChanged方法是如何工作的,但是如果执行lambda expression()=> Errors,它将返回_errors中包含的字符串而不是更改的属性的名称? So try to give directly the name of the property if the method exists.
因此,如果方法存在,请尝试直接提供属性的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.