stacker flow stacker flow - 2 months ago 18
C# Question

How To Prevent Binding Refresh

In my application, i bind the my string property to textblock tooltip.
The problem is the property that i bind is updating too frequently in runtime. So every time when it is updated tooltip refreshes even property value is same.

Following is the code:

<TextBlock Text="{Binding Key}" Margin="0,1" ToolTip="{Binding stringProperty}"/>


When stringProperty is updated tooltip refreshes. I want to bind property and i only want tooltip refresh when the updated value is different or maybe some long time after.

Answer

Something like this.

    public string stringProperty
    {
        get { return _stringProperty; }
        set
        {
            if (!_stringProperty.Equals(value))
            {
                _stringProperty = value;
                OnPropertyChanged("stringProperty");  //Notify UI only if there is new value
            }
        }
    }

If you want you can Compare string with Trim and CaseInsensitive