FrameworkElement.OnStyleChanged(Style, Style) 方法


当此元素上使用的样式更改时(将使布局失效)调用。Invoked when the style in use on this element changes, which will invalidate the layout.

protected public:
 virtual void OnStyleChanged(System::Windows::Style ^ oldStyle, System::Windows::Style ^ newStyle);
protected internal virtual void OnStyleChanged (System.Windows.Style oldStyle, System.Windows.Style newStyle);
abstract member OnStyleChanged : System.Windows.Style * System.Windows.Style -> unit
override this.OnStyleChanged : System.Windows.Style * System.Windows.Style -> unit
Protected Friend Overridable Sub OnStyleChanged (oldStyle As Style, newStyle As Style)



旧样式。The old style.


新样式。The new style.


此方法具有一个默认实现,该实现用于设置说明样式更改条件的内部标志。This method has a default implementation that sets an internal flag that notes the style changed condition.


通常不应重写此方法。You should not typically have to override this method. 涉及度量值或排列更改的样式的任何更改都将触发另一个呈现周期,假设 ArrangeOverride(Size)的典型实现 / MeasureOverride(Size)或默认值。Any change to a style that involves a measure or arrange change would already trigger another render cycle, assuming a typical implementation of ArrangeOverride(Size) / MeasureOverride(Size), or the defaults. 如果 ArrangeOverride(Size) / MeasureOverride(Size) 实现有意优化或支持部分更新,但仍希望更直接地将更改应用于样式,则 OnStyleChanged(Style, Style) 的替代可能适用。Overrides of OnStyleChanged(Style, Style) might be appropriate if your ArrangeOverride(Size) / MeasureOverride(Size) implementations were deliberately optimizing or supporting partial updates, but still wanted to apply changes to styles more directly. (部分更新会尝试避免对任何子元素上的 Measure(Size)Arrange(Rect) 进行多次增量调用。(The partial updates would be an attempt to avoid multiple incremental calls to Measure(Size) and Arrange(Rect) on any child elements).