Based on the documentation via MSDN...
You can also use InvalidateProperty to force re-evaluation of a binding against a data source that is not a
Yes. I have an idea.
The reason why your code doesn't work is that button asks for new value, but Binding object holds the old one as it hasn't got PropertyChanged notification. The changes chain in standart scenario looks like:
Payload.Timestamp -> Binding object -> Button.ContentProperty
In your scenario, when you call InvalidateProperty
chain is:
Binding object -> Button.ContentProperty
So, you should notify binding object that its source has been changed with next code:
private void Invalidate(object sender, RoutedEventArgs e)
{
_payload.Timestamp = DateTime.Now.Add(TimeSpan.FromHours(1)).ToLongTimeString();
Button b = sender as Button;
BindingExpression be = b.GetBindingExpression(Button.ContentProperty);
be.UpdateTarget();
}
As you can see, I even shouldn't call InvalidateProperty
, because the Binding mechanizm due to changed underlying source will automatically force Button to refresh content.