在我的应用程序中,我将我的字符串属性绑定到文本块工具提示。 问题是我绑定的属性在运行时更新太频繁。所以每次更新时,即使属性值相同,tooltip刷新也是如此。如何防止绑定刷新
以下是代码:
<TextBlock Text="{Binding Key}" Margin="0,1" ToolTip="{Binding stringProperty}"/>
当stringProperty更新提示刷新。我想要绑定属性,并且我只希望工具提示刷新时更新的值不同或可能很长时间后。
在我的应用程序中,我将我的字符串属性绑定到文本块工具提示。 问题是我绑定的属性在运行时更新太频繁。所以每次更新时,即使属性值相同,tooltip刷新也是如此。如何防止绑定刷新
以下是代码:
<TextBlock Text="{Binding Key}" Margin="0,1" ToolTip="{Binding stringProperty}"/>
当stringProperty更新提示刷新。我想要绑定属性,并且我只希望工具提示刷新时更新的值不同或可能很长时间后。
就是这样。
public string stringProperty
{
get { return _stringProperty; }
set
{
if (!_stringProperty.Equals(value))
{
_stringProperty = value;
OnPropertyChanged("stringProperty"); //Notify UI only if there is new value
}
}
}
如果你愿意,你可以Compare
串Trim
和CaseInsensitive
private string _stringProperty;
public string stringProperty
{
get { return _stringProperty; }
set
{
if (!ReferenceEquals(_stringProperty, value))
{
_stringProperty = value;
OnPropertyChanged("stringProperty");
}
}
}
如果使用ReferenceEquals
,它不会抛出NullReferenceException
如果_stringProperty
是null
。
其实它是程序的设计。它需要经常更新,因为它来自实时通信。我只是想阻止通知UI组件,即使绑定属性已更改。这有可能吗? –