共用方式為


CompositionScopedBatch 類別

定義

明確建立的作用中動畫或效果群組。

public ref class CompositionScopedBatch sealed : CompositionObject
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.LiftedContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class CompositionScopedBatch final : CompositionObject
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
class CompositionScopedBatch final : CompositionObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.LiftedContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class CompositionScopedBatch : CompositionObject
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
public sealed class CompositionScopedBatch : CompositionObject
Public NotInheritable Class CompositionScopedBatch
Inherits CompositionObject
繼承
Object Platform::Object IInspectable CompositionObject CompositionScopedBatch
屬性

範例

範圍批次

// The Green Square's completion events for the Offset and Opacity animations are aggregated
// The Rotation animation completion event is not aggregated
// When the aggregated events are completed OnBatchCompleted method is executed
public void BatchAnimations()
{
    // Create a Scoped batch to capture animation completion events
    _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

    // Executing the Offset animation and aggregating completion event
    ApplyOffsetAnimation(_greenSquare);

    // Suspending to exclude the following Rotation animation from the batch
    _batch.Suspend();

    // Executing the Rotation animation 
    ApplyRotationAnimation(_greenSquare);

    // Resuming the batch to collect additional animations
    _batch.Resume();

    // Executing the Opacity animation and aggregating completion event
    ApplyOpacityAnimation(_greenSquare);

    // Batch is ended and no objects can be added
    _batch.End();

    // Method triggered when batch completion event fires
    _batch.Completed += OnBatchCompleted;
}

備註

代表作用中動畫或效果的群組,並在群組的所有成員完成時觸發回呼。 CompositionScopedBatch 會明確建立,並用來指定要包含在單一範圍批次中的特定物件。

您可以建立多個 CompositionScopedBatch 實例,同時在多個批次中匯總物件。

建立

若要匯總特定動畫群組或以單一動畫完成事件為目標,您可以建立限定範圍的批次。 範圍批次是使用 Compositor.CreateScopedBatch 明確建立,用來指定要包含在單一批次中的特定物件。 範圍批次可以在任何執行緒上建立,而且不會系結至組合執行緒。 限定範圍的批次只會在其建立的執行緒內匯總物件。

CompositionScopedBatch myScopedBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

暫停和繼續

建立限定範圍的批次之後,所有已啟動的動畫都會匯總,直到批次明確暫停或使用 Suspend 或 End 函式結束為止。

CompositionScopedBatch 可能會以 Suspend 明確暫停,以便從該批次中排除物件。 當批次暫停時,可以藉由呼叫 Resume重新開啟。 呼叫 Suspend 函式會停止匯總動畫結束狀態,直到呼叫 Resume 為止。 這可讓您明確排除來自指定之批次的內容。

在以下範例中,鎖定 VisualA 位移屬性的動畫將不會納入批次中:

myScopedBatch.Suspend();
VisualA.StartAnimation("Offset", myAnimation);
myScopeBatch.Resume();

結束

CompositionScopedBatch 必須使用 End明確關閉。 關閉之後,就無法再暫停或繼續。 若要完成您的批次,您必須呼叫 End()。 如果沒有 End 呼叫,批次就會讓不斷進行收集的物件保持開啟。

下列程式碼片段和圖表顯示批次如何匯總動畫以追蹤結束狀態的範例。

請注意,在此範例中,動畫 1、3 和 4 具有由此批次追蹤的結束狀態,但動畫 2 則否。

myScopedBatch.End();
CompositionScopedBatch myScopedBatch = 	_compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
// Start Animation1
[…]
myScopedBatch.Suspend();
// Start Animation2 
[…]
myScopedBatch.Resume();
// Start Animation3
[…]
// Start Animation4
[…]
myScopedBatch.End();

限定範圍的批次包含動畫一、動畫三及動畫四,而將動畫二排除在限定範圍的批次之外

批次處理單一動畫的完成事件

如果您想要知道單一動畫何時結束,您必須建立範圍批次,只包含您設為目標的動畫。

例如:

CompositionScopedBatch myScopedBatch = 	_compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
Visual.StartAnimation("Opacity", myAnimation);
myScopedBatch.End();

擷取批次完成事件

批次處理一或多個動畫時,將會依照相同方式擷取批次完成事件。 您為目標批次的 Completed 事件註冊事件處理方法。

myScopedBatch.Completed += OnBatchCompleted;

批次狀態

您可以使用兩個屬性來判斷現有批次的狀態; IsActiveIsEnded

若鎖定的批次接受進行動畫彙總,則 IsActive 屬性會傳回 true。 批次暫停或結束時,IsActive 會傳回 false。

若您無法將動畫新增至該特定批次,則 IsEnded 屬性會傳回 true。 當您呼叫特定批次的明確呼叫 End 時,將會結束批次。

屬性

Comment

要與 CompositionObject 建立關聯的字串。

(繼承來源 CompositionObject)
Compositor

用來建立這個CompositionObjectCompositor

(繼承來源 CompositionObject)
DispatcherQueue

取得 CompositionObject 的 DispatcherQueue。

(繼承來源 CompositionObject)
ImplicitAnimations

附加至這個 物件的隱含動畫集合。

(繼承來源 CompositionObject)
IsActive

指出 CompositionScopedBatch 目前是否已開啟以供匯總的物件。

IsEnded

指出 CompositionScopedBatch 是否已關閉,而且無法再接受變更。

Properties

CompositionObject相關聯的屬性集合。

(繼承來源 CompositionObject)

方法

Close()

關閉 CompositionObject 並釋放系統資源。

(繼承來源 CompositionObject)
Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

(繼承來源 CompositionObject)
End()

關閉 CompositionScopedBatch當 CompositionScopedBatch關閉之後,就無法再暫停或繼續。

PopulatePropertyInfo(String, AnimationPropertyInfo)

定義可以產生動畫效果的屬性。

(繼承來源 CompositionObject)
Resume()

繼續匯總 CompositionScopedBatch中的物件。

StartAnimation(String, CompositionAnimation)

將動畫與物件的指定屬性連接,並啟動動畫。

(繼承來源 CompositionObject)
StartAnimation(String, CompositionAnimation, AnimationController)

將動畫與物件的指定屬性連接,並啟動動畫。

(繼承來源 CompositionObject)
StartAnimationGroup(ICompositionAnimationBase)

啟動動畫群組。

CompositionObject上的StartAnimationGroup 方法可讓您啟動 CompositionAnimationGroup。 群組中的所有動畫都會在 物件上同時啟動。

(繼承來源 CompositionObject)
StopAnimation(String)

中斷動畫與指定屬性的連接,並停止動畫。

(繼承來源 CompositionObject)
StopAnimationGroup(ICompositionAnimationBase)

停止動畫群組。

(繼承來源 CompositionObject)
Suspend()

暫停 在 CompositionScopedBatch中匯總物件。

TryGetAnimationController(String)

傳回在指定屬性上執行之動畫的 AnimationController。

(繼承來源 CompositionObject)

事件

Completed

一旦 CompositionScopedBatch中的所有動畫和效果都已完成,就會觸發事件。

適用於

另請參閱