FrameworkElement.DataContextChanged 事件

定义

在此元素的数据上下文更改时发生。Occurs when the data context for this element changes.

public:
 event System::Windows::DependencyPropertyChangedEventHandler ^ DataContextChanged;
public event System.Windows.DependencyPropertyChangedEventHandler DataContextChanged;
member this.DataContextChanged : System.Windows.DependencyPropertyChangedEventHandler 
Public Custom Event DataContextChanged As DependencyPropertyChangedEventHandler 

注解

有关数据上下文和数据绑定的说明,请参阅数据绑定概述For an explanation of data contexts and data binding, see Data Binding Overview.

重要

当元素的 DataContext 更改时,此元素上的所有数据绑定属性都可能会受到影响。When the DataContext for an element changes, all data-bound properties on this element are potentially affected. 这适用于作为逻辑树中当前元素的子元素的所有元素,这些元素继承数据上下文以及当前元素本身。This applies to any elements that are child elements of the current element in the logical tree, which inherit the data context, and also the current element itself. 所有此类现有绑定都必须重新解释新 DataContext,并将重新计算绑定结果。All such existing bindings must re-interpret the new DataContext and will reevaluate the binding results. 数据绑定引擎并不确定这些 reevaluations 的顺序,这与引发 DataContextChanged 事件相关。The data binding engine is not deterministic about the order of these reevaluations, relative to the raising of the DataContextChanged event. Reevaluations 可以在事件之前、事件之后或任何组合中发生。The reevaluations can occur before the event, after the event, or in any mixture.

适用于

另请参阅