![](/img/trans.png)
[英]WPF Bound TextBox value not updating when other TextBox is changed
[英]WPF - Bound Control Not Updating When Property Changed?
我已经将TextBox的Text属性绑定到基础对象的属性,并且看起来工作得很好。 不幸的是,当我以编程方式更改属性的值时,它似乎并未在GUI上更新。
这是属性:
public string SealedDate
{
get
{
string result = string.Empty;
if (_DACase.SealedDate != DateTime.MinValue)
{
result = Formatting.FormatDate(_DACase.SealedDate);
}
return result;
}
set
{
DateTime theDate = DateTime.MinValue;
if (DateTime.TryParse(value, out theDate)
&& _DACase.SealedDate != theDate)
{
_DACase.SealedDate = theDate;
base.OnChanged(); //fires event so I know the value of the object has changed
}
}
}
当设置另一个属性时,将设置该属性的值:
public bool IsSealed
{
get
{
return _DACase.SealedId > 0
|| _DACase.SealedDate != DateTime.MinValue;
}
set
{
if (value != (_DACase.SealedId > 0 || _DACase.SealedDate != DateTime.MinValue))
{
if (value)
{
this.SealedId = Authentication.CurrentUser.Id;
this.SealedDate = Formatting.FormatDate(DateTime.Now);
}
else
{
this.SealedId = 0;
this.SealedDate = DateTime.MinValue.ToString();
}
base.OnChanged();
}
}
}
我认为应该不更新的TextBox的XAML:
<TextBox Name="txtSealedDate" Text="{Binding SealedDate}" Grid.Column="5" Grid.Row="3" IsReadOnly="True" />
弗拉德的解决方案(在评论中)是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.