语言

VisualStateManager.GoToStateCore 方法

定义

在派生类中重写时,在状态之间转换控件。

protected:
 virtual bool GoToStateCore(Control ^ control, FrameworkElement ^ templateRoot, Platform::String ^ stateName, VisualStateGroup ^ group, VisualState ^ state, bool useTransitions) = GoToStateCore;
bool GoToStateCore(Control const& control, FrameworkElement const& templateRoot, winrt::hstring const& stateName, VisualStateGroup const& group, VisualState const& state, bool const& useTransitions);
protected virtual bool GoToStateCore(Control control, FrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions);
function goToStateCore(control, templateRoot, stateName, group, state, useTransitions)
Protected Overridable Function GoToStateCore (control As Control, templateRoot As FrameworkElement, stateName As String, group As VisualStateGroup, state As VisualState, useTransitions As Boolean) As Boolean

参数

control
Control

在状态之间转换的控件。

templateRoot
FrameworkElement

控件 ControlTemplate 的根元素。

stateName
String

Platform::String

winrt::hstring

要转换到的状态的名称。

group
VisualStateGroup

状态所属的 VisualStateGroup 。

state
VisualState

要转换到的状态的表示形式。

useTransitions
Boolean

bool

true 使用 VisualTransition 在状态之间转换;否则,为 false.

返回

Boolean

bool

true 如果控件成功转换为新状态,则为否则,为 false.

注解

此 API 是定义自定义 VisualStateManager 行为的方案的一部分。 重写 GoToStateCore 自定义类行为中的状态行为。

若要引用自定义 VisualStateManager 类,请在想要在其中使用自定义VisualStateManager类行为的任意控件模板中设置 VisualStateManager.CustomVisualStateManager 附加属性的值。 通常通过 Application.Resources 中的默认 XAML 构造创建自定义VisualStateManager类的实例。 VisualStateManager.CustomVisualStateManager然后使用对自定义VisualStateManager资源的键的 {StaticResource} 标记扩展引用来设置附加属性。

继承者的注释

当自定义 VisualStateManager 类的使用者调用 GoToState 以更改控件的视觉状态时,这是你重写的默认行为:+ 如果 VisualState 命名为 stateNameStoryboard,则情节提要将开始。

  • 如果控件在新请求的状态之前使用的 VisualState 具有 情节提要,该情节提要将停止。
  • 如果 VisualState 中 stateName 不存在 group,则实现应返回 false。
  • 如果控件已在 VisualState 中请求 stateName,则你的实现应返回 true。

有关默认行为的详细信息,请参阅 GoToState。

视觉状态更改的事件

当控件开始根据 GoToState 调用的请求转换状态时,CurrentStateChanging 将触发。 如果 VisualTransition 应用于状态更改,则转换开始时会发生此事件。

当控件处于 GoToState 调用请求的状态后,CurrentStateChanged 将触发,就像新的 Storyboard 开始一样。 新情节提要完成时不会触发任何事件。

如果未应用 VisualTransition , 则 CurrentStateChanging 和 CurrentStateChanged 会连续快速触发,但如果两者都发生,则会按该顺序进行保证。

但是,如果状态更改转换被新的 GoToState 调用中断,则对于第一次状态转换,永远不会引发 CurrentStateChanged 事件。 为下一次请求的状态更改触发新的事件系列。

重写 RaiseCurrentStateChanged 和 RaiseCurrentStateChanging 的行为是可选的:默认实现引发事件的方式和时间可能足以满足自定义类的需求。

适用于

另请参阅