FrameworkElement.GoToElementStateCore(String, Boolean) 方法

定義

在衍生類別中實作時,可在程式碼中啟用控制項範本的個別狀態建構,而不是在控制項啟動時載入所有狀態的 XAML。

protected:
 virtual bool GoToElementStateCore(Platform::String ^ stateName, bool useTransitions) = GoToElementStateCore;
bool GoToElementStateCore(winrt::hstring const& stateName, bool const& useTransitions);
protected virtual bool GoToElementStateCore(string stateName, bool useTransitions);
function goToElementStateCore(stateName, useTransitions)
Protected Overridable Function GoToElementStateCore (stateName As String, useTransitions As Boolean) As Boolean

參數

stateName
String

Platform::String

winrt::hstring

要切換的目標狀態。

useTransitions
Boolean

bool

true 表示使用 VisualTransition 在狀態之間轉換。 false 表示略過使用轉換,並直接移至要求的狀態。 預設值為 false

傳回

Boolean

bool

true 如果控制項成功轉換至新狀態,或已經使用該狀態,則為 ;否則為 false

備註

的預設實作 FrameworkElement.GoToElementStateCore 提供透過呼叫 VisualStateManager.GoToState存取的一般狀態變更行為,以及任何 XAML 控制項的預設控制項範本/視覺狀態載入行為。 只有在您已準備好在執行時間建構程式碼中控制項的視覺化樹狀結構時,才應該覆寫 FrameworkElement.GoToElementStateCore 。 這包括來自內容屬性、子項目集合等內容的任何呈現方式。

針對自訂控制項中的一般狀態變更邏輯,您應該使用 VisualStateManager.GoToState。 的預定案例 FrameworkElement.GoToElementStateCore 較為有限,特別適用于想要優化建立 ListViewItemGridViewItem 視覺化樹狀結構之範本或邏輯的應用程式或控制項,並呈現內容。

VisualStateManager.GoToState 具有稍微不同的簽章,因為它是靜態公用程式 API,並使用 控制項 參數來指定要套用狀態變更的控制項。 FrameworkElement.GoToElementStateCore 會使用呼叫物件來取得這項資訊。

適用於

另請參閱