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.

 
 
 
 
 
(0)
6,756 times
Add to favorites
2/1/2011
E-mail Twitter del.icio.us Digg Facebook
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Class="IPCCSSampleCSharp.HomePage">

  <StackPanel>

    <TextBlock FontSize="15" FontWeight="DemiBold" Margin="10">
      Remember Per-Page State Across Page Navigations
    </TextBlock>

    <TextBlock Margin="10,0,10,10">
      <TextBlock FontWeight="DemiBold">
        Change the text's zoom and vertical scroll position, navigate away from this page, then navigate back.
      </TextBlock>
      <LineBreak />
      - <Hyperlink NavigateUri="AnotherPage.xaml">Navigate to another page in this XBAP</Hyperlink>
      <LineBreak />
      - <Hyperlink NavigateUri="pack://siteoforigin:,,,/simple.html">Navigate away from this page to an HTML page</Hyperlink>
    </TextBlock>

    <Grid Margin="10,0,10,10">

      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="10" />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="10" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <TextBlock Grid.Column="0" Grid.Row="0" FontWeight="DemiBold">Document:</TextBlock>
      <Border Grid.Column="0" Grid.Row="1" Padding="5" BorderThickness="2" BorderBrush="Black">
        <ScrollViewer Name="documentScrollViewer" Width="400" Height="400">
          <StackPanel>
            <StackPanel.LayoutTransform>
              <ScaleTransform ScaleX="{Binding ElementName=zoomSlider, Path=Value}"
                              ScaleY="{Binding ElementName=zoomSlider, Path=Value}">
              </ScaleTransform>
            </StackPanel.LayoutTransform>
            <TextBlock TextWrapping="Wrap">
              <Bold>Neptune</Bold> (planet), major planet in the solar system, eighth planet
              from the Sun and fourth largest in diameter.  Neptune maintains an almost constant
              distance, about 4,490 million km (about 2,790 million mi), from the Sun.  Neptune
              revolves outside the orbit of Uranus and for most of its orbit moves inside the
              elliptical path of the outermost planet Pluto (see Solar System). Every 248 years,
              Pluto’s elliptical orbit brings the planet inside Neptune’s nearly circular orbit
              for about 20 years, temporarily making Neptune the farthest planet from the Sun.
              The last time Pluto’s orbit brought it inside Neptune’s orbit was in 1979. In
              1999 Pluto’s orbit carried it back outside Neptune’s orbit.
              <LineBreak/>
              <LineBreak/>
              Astronomers believe Neptune has an inner rocky core that is surrounded by a vast
              ocean of water mixed with rocky material. From the inner core, this ocean extends
              upward until it meets a gaseous atmosphere of hydrogen, helium, and trace amounts
              of methane. Neptune has four rings and 11 known moons. Even though Neptune's volume
              is 72 times Earth’s volume, its mass is only 17.15 times Earth’s mass. Because of
              its size, scientists classify Neptune—along with Jupiter, Saturn, and Uranus—as
              one of the giant or Jovian planets (so-called because they resemble Jupiter).
              <LineBreak/>
              <LineBreak/>
              Mathematical theories of astronomy led to the discovery of Neptune. To account for
              wobbles in the orbit of the planet Uranus, British astronomer John Couch Adams and
              French astronomer Urbain Jean Joseph Leverrier independently calculated the existence
              and position of a new planet in 1845 and 1846, respectively. They theorized that the
              gravitational attraction of this planet for Uranus was causing the wobbles in Uranus’s
              orbit. Using information from Leverrier, German astronomer Johann Gottfried Galle first
              observed the planet in 1846.
            </TextBlock>
          </StackPanel>
        </ScrollViewer>
      </Border>

      <TextBlock Grid.Column="2" Grid.Row="0" FontWeight="DemiBold">Zoom:</TextBlock>
      <Slider Name="zoomSlider" Grid.Column="2" Grid.Row="1" Minimum="0.5" Maximum="5" Value="1" Orientation="Vertical" TickFrequency="0.5" TickPlacement="BottomRight" />

      <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Orientation="Horizontal">
        <Label FontWeight="DemiBold">Number of Times Read:</Label>
        <Label Name="readCountLabel" />
      </StackPanel>
      
    </Grid>

  </StackPanel>

</Page>