Is there a way to refresh all bindings in WPF?

后端 未结 3 767
盖世英雄少女心
盖世英雄少女心 2021-02-07 01:38

If my code looks somewhat like the code beneath, would it be possible to refresh all bindings directly or would I have to hard-code all the bindings to refresh?

Service-

相关标签:
3条回答
  • 2021-02-07 01:46

    How about making "data" a dependency property. Binding your DataContext to that will make your bindings update when you re-assign "data".

    0 讨论(0)
  • 2021-02-07 01:54

    Found the answer, seems like that calling PropertyChanged with the PropertyChangedEventArgs property name set to "" refreshes all bindings.
    The DataContext changing worked too, although this felt a bit "cleaner".

    0 讨论(0)
  • 2021-02-07 02:07

    You can null then re-set the DataContext of the parent object.

    DataContext = null;
    DataContext = data;
    
    0 讨论(0)
提交回复
热议问题