DependencyObject.InvalidateProperty not working

后端 未结 3 2027
暖寄归人
暖寄归人 2021-01-11 12:16

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

3条回答
  •  梦毁少年i
    2021-01-11 12:41

    we never got it working either, here's the function which does the trick:

    private void InvalidateProperty(DependencyProperty property,
        FrameworkElement container)
    {
        container.SetBinding(property, 
            container.GetBindingExpression(property).ParentBinding);
    }
    

    And here's how we call it:

    private void Invalidate(object sender, RoutedEventArgs e)
    {
        _payload.Timestamp = DateTime.Now.Add(TimeSpan.FromHours(1)).ToLongTimeString();
    
        Button b = sender as Button;
    
        //b.InvalidateProperty(Button.ContentProperty);
        this.InvalidateProperty(Button.ContentProperty, b);
    }
    

    I also had to set DataContext to _payload.

提交回复
热议问题