Remember A Single Set of State Across Page Instances

This sample illustrates how to remember multiple items of page state across page instances by using IProvideCustomContentState and CustomContentState. Building the Sample Install the Windows Software Development Kit (SDK) and open its build environment command window.

6,756 times
Add to favorites
E-mail Twitter Digg Facebook
using System;
using System.ComponentModel;
using System.Windows.Navigation;
using System.Windows.Data;
using System.Windows.Controls;

namespace IPCCSSampleCSharp
    public class CustomPageContentState : CustomContentState
        double verticalOffset;
        int readCount;

        public CustomPageContentState(double verticalOffset, int readCount)
            // "Remember" vertical offset and read count
            this.verticalOffset = verticalOffset;
            this.readCount = readCount;

            // Note: The Value of the zoom scrollbar is automatically saved because
            // the dependency property has the Journal metadata flag, and the control is
            // placed in the primary logical tree.
            // Neither ScrollViewer nor Label, however, is not automatically journaled.

        public override void Replay(NavigationService navigationService, NavigationMode mode)
            // Apply previous scroll offset
            ScrollViewer scrollViewer = ((HomePage)navigationService.Content).documentScrollViewer;

            // Increment previous read count and apply
            Label label = ((HomePage)navigationService.Content).readCountLabel;
            label.Content = (++this.readCount);