VisualStateManager.GoToState(FrameworkElement, String, Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
转换两种状态之间的控件。 使用此方法转换具有 . ControlTemplate. 的控件的状态。
public:
static bool GoToState(System::Windows::FrameworkElement ^ control, System::String ^ stateName, bool useTransitions);
public static bool GoToState(System.Windows.FrameworkElement control, string stateName, bool useTransitions);
static member GoToState : System.Windows.FrameworkElement * string * bool -> bool
Public Shared Function GoToState (control As FrameworkElement, stateName As String, useTransitions As Boolean) As Boolean
参数
- control
- FrameworkElement
在状态之间转换的控件。
- stateName
- String
要转换到的状态。
- useTransitions
- Boolean
返回
true 如果控件已成功转换为新状态,则为否则,为 false.
例外
示例
以下示例演示了一个控件,该控件使用 GoToState 该方法在状态之间转换。 有关整个示例,请参阅 创建具有可自定义外观的控件。
private void UpdateStates(bool useTransitions)
{
if (Value >= 0)
{
VisualStateManager.GoToState(this, "Positive", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Negative", useTransitions);
}
if (IsFocused)
{
VisualStateManager.GoToState(this, "Focused", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Unfocused", useTransitions);
}
}
Private Sub UpdateStates(ByVal useTransitions As Boolean)
If Value >= 0 Then
VisualStateManager.GoToState(Me, "Positive", useTransitions)
Else
VisualStateManager.GoToState(Me, "Negative", useTransitions)
End If
If IsFocused Then
VisualStateManager.GoToState(Me, "Focused", useTransitions)
Else
VisualStateManager.GoToState(Me, "Unfocused", useTransitions)
End If
End Sub
注解
GoToState如果要更改控件中使用该VisualStateManager控件ControlTemplate中的状态,请调用该方法。 GoToElementState调用该方法以更改元素外部ControlTemplate的状态(例如,如果在单个VisualStateManager元素中使用UserControl状态)。