CustomContentState 類別

定義

CustomContentState 可以巡覽單一來源內容的不同狀態,不用重新載入各個後續巡覽的來源內容。

public ref class CustomContentState abstract
[System.Serializable]
public abstract class CustomContentState
public abstract class CustomContentState
[<System.Serializable>]
type CustomContentState = class
type CustomContentState = class
Public MustInherit Class CustomContentState
繼承
CustomContentState
屬性

範例

以下是覆寫 JournalEntryName 的實作 CustomContentState 範例。

using System;
using System.Windows.Controls;
using System.Windows.Navigation;
[Serializable]
public class MyCustomContentState : CustomContentState
{
    string dateCreated;
    TextBlock dateTextBlock;

    public MyCustomContentState(string dateCreated, TextBlock dateTextBlock)
    {
        this.dateCreated = dateCreated;
        this.dateTextBlock = dateTextBlock;
    }

    public override string JournalEntryName
    {
        get
        {
            return "Journal Entry " + this.dateCreated;
        }
    }

    public override void Replay(NavigationService navigationService, NavigationMode mode)
    {
        this.dateTextBlock.Text = this.dateCreated;
    }
}

Imports System.Windows.Controls
Imports System.Windows.Navigation
<Serializable>
Public Class MyCustomContentState
    Inherits CustomContentState
    Private dateCreated As String
    Private dateTextBlock As TextBlock

    Public Sub New(ByVal dateCreated As String, ByVal dateTextBlock As TextBlock)
        Me.dateCreated = dateCreated
        Me.dateTextBlock = dateTextBlock
    End Sub

    Public Overrides ReadOnly Property JournalEntryName() As String
        Get
            Return "Journal Entry " & Me.dateCreated
        End Get
    End Property

    Public Overrides Sub Replay(ByVal navigationService As NavigationService, ByVal mode As NavigationMode)
        Me.dateTextBlock.Text = Me.dateCreated
    End Sub
End Class

備註

根據預設, NavigationService 不會將內容物件的實例儲存在流覽歷程記錄中。 相反地, NavigationService 每次使用流覽歷程記錄流覽至內容物件時,就會建立內容物件的新實例。 此行為的設計目的是要避免大量和大量內容巡覽至時耗用過多的記憶體。 因此,內容的狀態不會從一個流覽到下一個導覽中記住。 不過,WPF 可讓您將一段自訂狀態與內容片段的流覽歷程記錄專案產生關聯。

與導覽歷程記錄專案相關聯的自訂狀態必須是衍生自 CustomContentState 的類別。 您可以使用下列其中一種技術,將物件與導覽歷程記錄專案產生關聯 CustomContentState

注意

如果您呼叫 AddBackEntry 方法,則必須處理 Navigating 事件或實 IProvideCustomContentState 作 。

流覽歷程記錄專案巡覽至時,WPF 會檢查自訂物件是否 CustomContentState 與其相關聯。 如果是,它會呼叫 Replay 以允許自訂 CustomContentState 物件套用先前導覽所記住的狀態。

自訂 CustomContentState 類別可以覆寫 JournalEntryName ,以變更物件相關聯之流覽歷程記錄專案 CustomContentState 所顯示的名稱。 傳回的值 JournalEntryName 可從 Internet Explorer 7、 NavigationWindow Frame) (各種導覽器的導覽 UI 中看到。

衍生自 CustomContentState 的類別必須可序列化,這表示它至少必須以 SerializableAttribute 增強,並選擇性地實 ISerializable 作 。

重要

當您將資訊儲存在自訂內容狀態時,如果不想將內容保留在記憶體中,則無法儲存您記住狀態之頁面實例的任何參考。 這可防止 WPF 釋放頁面實例,並破壞預設導覽歷程記錄行為的目的。 如果您必須這樣做,請考慮改用 KeepAlive

建構函式

CustomContentState()

初始化 CustomContentState 類別的新執行個體。

屬性

JournalEntryName

儲存在巡覽記錄中之內容的名稱。 的值 JournalEntryName 會從 NavigationWindowFrame 和 Windows Internet Explorer 7 流覽 UI 顯示。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Replay(NavigationService, NavigationMode)

在發生巡覽時呼叫,以重新套用狀態至內容。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱