Silverlight John Carter of Mars

.Silverlight John Carter of Mars


Screen Capture of Mars Example Program



.Edgar Rice Burroughs Mars Series

I created the Silverlight program below while studying for the 70-506 exam. It uses animation storyboards, transformations, page navigation, data binding, file I/O, a datagrid and other user controls. Check boxes are updated to indicate the pages viewed. The drop down lists can be updated to rate the book. It also contains a static class for global data storage. The buttons and links are scaled up on mouse-over and momentarily change to green when clicked. The theme of the program is Edgar Rice Burrough's Mars series of books. If you have Silverlight installed on your browser, the planet Mars rotates on the top left corner of the screen as a space ship approaches from the right. The program contains three pages; each page has the book cover and first chapter of the first three books in the series. A data grid control shows the first five books in the series and display addition information when a row is selected. The source code for the program is listed below.

Get Microsoft Silverlight

Mars Silverlight Application - Try the buttons, controls, and data grid

App.xaml.cs

/*** App.xaml.cs ***/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Mars2.BookDataStorage;

namespace Mars2
{
    public partial class App : Application
    {
        public App()
        {           
            InitializeComponent();
            this.Startup += this.Application_Startup;
            this.UnhandledException += this.Application_UnhandledException;
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();
            BookData myBookData = new BookData();
        }

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // a ChildWindow control.
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled.
                // For production applications this error handling should be replaced with something that will
                // report the error to the website and stop the application.
                e.Handled = true;
                ChildWindow errorWin = new ErrorWindow(e.ExceptionObject);
                errorWin.Show();
            }
        }
    }
}

MainPage.xaml

/*** MainPage.xaml ***/
<UserControl
    x:Class="Mars2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Viewbox>
        <Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootGridStyle}">
  
            <Border x:Name="ContentBorder" Style="{StaticResource ContentBorderStyle}">

            <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}"
                              Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">
                <navigation:Frame.UriMapper>
                  <uriMapper:UriMapper>
                    <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
                    <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
                  </uriMapper:UriMapper>
                </navigation:Frame.UriMapper>
            </navigation:Frame>
        </Border>

        <Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}">

            <Border x:Name="BrandingBorder" Style="{StaticResource BrandingBorderStyle}">
                <StackPanel x:Name="BrandingStackPanel" Style="{StaticResource BrandingStackPanelStyle}">
                    <StackPanel.Resources>
                        <Storyboard x:Name="marsStoryboard">
                                <DoubleAnimation
                                Storyboard.TargetName="marsTransform"
                                Storyboard.TargetProperty="Angle"
                                From="0" To="360" Duration="0:0:30"
                                RepeatBehavior="Forever" />
                        </Storyboard>
                        <Storyboard x:Name="shipStoryboard">
                            <DoubleAnimation
                                Storyboard.TargetName="shipTransform"
                                            Storyboard.TargetProperty="X"
                                            From="600"
                                            To="-170"
                                            Duration="0:1:33"
                                            RepeatBehavior="Forever">
                            </DoubleAnimation>
                        </Storyboard>
                        </StackPanel.Resources>

                    <Image x:Name="imgMars" Source="Images/Marsf.png" Stretch="None" RenderTransformOrigin="0.5,0.5" >
                        <Image.RenderTransform>
                            <RotateTransform x:Name="marsTransform" Angle="1" CenterX="0" CenterY="0" />
                        </Image.RenderTransform>
                    </Image>
                   
                    <TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}"
                               Text=" John Carter of Mars"/>

                    <Polygon x:Name="polyShip" Points="10,10 12.5,12.5 10.0,20.0 7.5,12.5"
                            Stroke="Yellow" StrokeThickness="2" Fill="Black">
                        <Polygon.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
                                    <RotateTransform Angle="90" />
                                    <TranslateTransform x:Name="shipTransform" X="0" Y="0"/>
                            </TransformGroup>
                        </Polygon.RenderTransform>
                    </Polygon>
                </StackPanel>
            </Border>

            <Border x:Name="LinksBorder" Style="{StaticResource LinksBorderStyle}">
              
                <StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">

                    <HyperlinkButton x:Name="homeLink" RenderTransformOrigin="0.5, 0.5" Margin="20,0,0,0"
                                     NavigateUri="/Home" TargetName="ContentFrame" Content="Home"/>

                    <HyperlinkButton x:Name="princessLink" Click="princessLink_Click" Margin="15,0,15,0"
                                     NavigateUri="/Princess" TargetName="ContentFrame" Content="Princess"/>

                    <HyperlinkButton x:Name="godsLink" Click="godsLink_Click"
                                     NavigateUri="/Gods" TargetName="ContentFrame" Content="Gods"/>

                    <HyperlinkButton x:Name="warlordsLink" Click="warlordsLink_Click" Margin="15,0,15,0"
                                     NavigateUri="/Warlords" TargetName="ContentFrame" Content="Warlords"/>

                </StackPanel>
            </Border>
        </Grid>           
    </Grid>
    </Viewbox>
</UserControl>

MainPage.xaml.cs

/*** MainPage.xaml.cs ***/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Mars2.BookDataStorage;


namespace Mars2
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();           
            marsStoryboard.Begin();
            shipStoryboard.Begin();
        }

        // After the Frame navigates, ensure the HyperlinkButton representing the current page is selected
        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {
            foreach (UIElement child in LinksStackPanel.Children)
            {
                HyperlinkButton hb = child as HyperlinkButton;
                if (hb != null && hb.NavigateUri != null)
                {
                    if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
                    {
                        VisualStateManager.GoToState(hb, "ActiveLink", true);
                    }
                    else
                    {
                        VisualStateManager.GoToState(hb, "InactiveLink", true);
                    }
                }
            }
        }

        // If an error occurs during navigation, show an error window
        private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            ChildWindow errorWin = new ErrorWindow(e.Uri);
            errorWin.Show();
        }

        private void princessLink_Click(object sender, RoutedEventArgs e)
        {
            // Mark book as viewed
            BookData.pIsChecked = true;           
        }

        private void godsLink_Click(object sender, RoutedEventArgs e)
        {
            // Mark book as viewed
            BookData.gIsChecked = true;
        }

        private void warlordsLink_Click(object sender, RoutedEventArgs e)
        {
            // Mark book as viewed
            BookData.wIsChecked = true;
        }

    }
}

Home.xaml

/*** Home.xaml***/
<navigation:Page     
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:my="clr-namespace:Mars2.BookDataStorage"                             
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="Mars2.Home"                             
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    Title="Home"
    Style="{StaticResource PageStyle}"
    NavigationCacheMode="Required">


    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <my:BookData x:Key="bookData" />
        </Grid.Resources>

        <Grid x:Name="BookDetails" ShowGridLines="False">
            <Grid.RowDefinitions>
                <RowDefinition Height="8*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Column="0" Grid.Row="0" x:Name="ContentStackPanel"  Grid.RowSpan="5" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Image Source="/Mars2;component/Images/Under_the_moon_of_Mars.jpg" Width="250" Height="250"/>
                <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"
                                       Text="Original publication of A Princess of Mars, series titled Under the moons of Mars" Width="300" FontSize="7"/>
                <TextBlock x:Name="ContentText2" Style="{StaticResource ContentTextStyle}"
                       Text="   All-Story Magazine, February 1912 by Edgar Rice Burroughs [Public domain]" Width="300" FontSize="7" Margin="0,0,0,2"/>
            </StackPanel>

            <Image x:Name ="dataGridImage" Source="{Binding Image}" >
            </Image>

            <TextBlock Grid.Row="2" Grid.Column="1" Text="Princess" FontSize="14"/>
            <TextBlock Grid.Row="3" Grid.Column="1" Text="Gods" FontSize="14"/>
            <TextBlock Grid.Row="4" Grid.Column="1" Text="Warlords" FontSize="14"/>

            <TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Text="Book" TextDecorations="Underline"/>
            <TextBlock Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" Text="Viewed" TextDecorations="Underline"/>
            <TextBlock Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Text="Liked" TextDecorations="Underline" Margin="0,0,0,0" />
            <TextBlock Grid.Row="1" Grid.Column="4" HorizontalAlignment="Center" Text="Go To Book" TextDecorations="Underline"/>

            <CheckBox x:Name="chkPrincess" Content=""  Grid.Column="2"  Grid.Row="2" Loaded="chkPrincess_Loaded" IsChecked="{Binding pIsChecked, Source={StaticResource bookData}}"                                                                                                                                      
                      VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" IsEnabled="False"/>
            <CheckBox x:Name="chkGods" Content="" Grid.Column="2"  Grid.Row="3" Loaded="chkGods_Loaded" IsChecked="{Binding gIsChecked, Source={StaticResource bookData}}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" IsEnabled="False"/>
            <CheckBox x:Name="chkWarlords" Content="" Grid.Column="2"  Grid.Row="4" Loaded="chkWarlords_Loaded" IsChecked="{Binding wIsChecked, Source={StaticResource bookData}}" VerticalAlignment="Center"  HorizontalAlignment="Center" Margin="0,0,0,0" IsEnabled="False"/>

            <ComboBox x:Name="cboPrincess"  Grid.Column="3" Grid.Row="2" Margin="10,2,10,2" SelectedIndex="0"  VerticalAlignment="Top" >
                <ComboBoxItem Content=" "/>
                <ComboBoxItem Content="Yes"/>
                <ComboBoxItem Content="No"/>
            </ComboBox>
            <ComboBox x:Name="cboGods"  Grid.Column="3" Grid.Row="3" Margin="10,2,10,2" SelectedIndex="0"  VerticalAlignment="Top" >
                <ComboBoxItem Content=" "/>
                <ComboBoxItem Content="Yes"/>
                <ComboBoxItem Content="No"/>
            </ComboBox>
            <ComboBox x:Name="cboWarlords"  Grid.Column="3" Grid.Row="4" Margin="10,2,10,2" SelectedIndex="0"  VerticalAlignment="Top" >
                <ComboBoxItem Content=" "/>
                <ComboBoxItem Content="Yes"/>
                <ComboBoxItem Content="No"/>
            </ComboBox>

            <Button x:Name ="btnPrincess" Content="Princess" Grid.Column="4"  Grid.Row="2" HorizontalAlignment="Center" Margin="2,1,2,5" VerticalAlignment="Top" Width="70" Click="Princess_Click" />
            <Button x:Name ="btnGods" Content="Gods" Grid.Column="4"  Grid.Row="3" HorizontalAlignment="Center" Margin="2,1,2,5" Width="70" Click="Gods_Click" />
            <Button x:Name ="btnWarlords" Content="Warlords" Grid.Column="4"  Grid.Row="4" HorizontalAlignment="Center" Margin="2,1,2,5" VerticalAlignment="Top" Width="70" Click="Warlords_Click" />
           
            <sdk:DataGrid x:Name="myDataGrid" Grid.ColumnSpan="4" Grid.Column="1"  VerticalAlignment="Top" Margin="0,0,0,25" Height="180" Width="auto"
                          SelectedItem="{Binding Book}"
                          HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" MouseLeftButtonUp="myDataGrid_MouseLeftButtonUp">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn Header="Image" SortMemberPath="Image">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image x:Name ="dataGridImage" Source="{Binding Image}" >
                                </Image>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="Auto"/>
                    <sdk:DataGridTextColumn Header="Published" Binding="{Binding Published}" Width="Auto"/>
                    <sdk:DataGridTextColumn Header="Narrator" Binding="{Binding Narrator}" Width="Auto"/>                   
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>           
        </Grid>
    </Grid>
</navigation:Page>

Home.xaml.cs

/*** Home.xaml.cs ***/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Mars2.BookDataStorage;
using Mars2.Views;

namespace Mars2
{
    public partial class Home : Page
    {

        public Home()
        {
            InitializeComponent();
            List<Book> books = GetBooks();
            myDataGrid.ItemsSource = books;          
        }

        private List<Book> GetBooks()
        {
            List<Book> books = new List<Book>();
            books.Add(new Book() { Image = "/Mars2;component/Images/Princess_of_Mars_Small.png", Image_Large = "/Images/Princess_of_Mars.png", Name = "A Princess of Mars", Published = "1917", Narrator = "John Carter", Description = "A Princess of Mars (1917) is a science fantasy novel by Edgar Rice Burroughs, the first of his Barsoom series. Full of swordplay and daring feats, the novel is considered a classic example of 20th century pulp fiction. John Carter, a Confederate veteran of the American Civil War, goes prospecting in Arizona immediately after the war's end. Having struck a rich vein of gold, he runs afoul of the Apaches. While attempting to evade pursuit by hiding in a sacred cave, he is mysteriously transported to Mars, called Barsoom by its inhabitants." });
            books.Add(new Book() { Image = "/Mars2;component/Images/Gods_of_Mars_Small.png", Image_Large = "/Images/Gods_of_Mars.png", Name = "Gods of Mars", Published = "1918", Narrator = "John Carter", Description = "The Gods of Mars is a 1918 Edgar Rice Burroughs science fantasy novel, the second of his famous Barsoom series. It was first published in All-Story as a five-part serial in the issues for JanuaryMay 1913. At the end of the first book, A Princess of Mars, John Carter is unwillingly transported back to Earth. The Gods of Mars begins with his arrival back on Barsoom (Mars) after a ten-year separation from his wife Dejah Thoris, his unborn child, and the Red Martian people of the nation of Helium, whom he has adopted as his own." });
            books.Add(new Book() { Image = "/Mars2;component/Images/Warlord_of_Mars_Small.png", Image_Large = "/Images/Warlord_of_Mars.png", Name = "The Warlord of Mars", Published = "1919", Narrator = "John Carter", Description = "The Warlord of Mars is a science fantasy novel written by Edgar Rice Burroughs, the third of his famous Barsoom series. This novel continues where the previous one in the series, The Gods of Mars abruptly ended. At the end of the previous book, John Carter's wife, the princess Dejah Thoris, is imprisoned in the Temple of the Sun by the vile pretender goddess Issus.  It is said one has to wait an entire Barsoomian year before the room the prisoner is in revolves back to the entrance." });
            books.Add(new Book() { Image = "/Mars2;component/Images/Maid_of_Mars_Small.png", Image_Large = "/Images/Maid_of_Mars.png", Name = "Thuvia, Maid of Mars", Published = "1920", Narrator = "John Carter", Description = "Thuvia, Maid of Mars is a science fantasy novel by Edgar Rice Burroughs, the fourth of the Barsoom series. The principal characters are the Son of John Carter of Mars, Carthoris, and Thuvia of Ptarth, each of whom appeared in the previous two novels. In this novel the focus shifts from John Carter, Warlord of Mars, and Dejah Thoris of Helium, protagonists of the first three books in the series, to their son, Carthoris, prince of Helium, and Thuvia, princess of Ptarth." });
            books.Add(new Book() { Image = "/Mars2;component/Images/Chessmen_of_Mars_Small.png", Image_Large = "/Images/Chessmen_of_Mars.png", Name = "The Chessmen of Mars", Published = "1922", Narrator = "John Carter", Description = "The Chessmen of Mars is an Edgar Rice Burroughs science fantasy novel, the fifth of his famous Barsoom series. Burroughs began writing it in January, 1921, and the finished story was first published in Argosy All-Story Weekly as a six-part serial. In this novel Burroughs focuses on a younger member of the family established by John Carter and Dejah Thoris, protagonists of the first three books in the series. The heroine this time is their daughter Tara, princess of Helium, whose hand is sought by the gallant Gahan, Jed (prince) of Gathol." });
            return books;
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        private void chkPrincess_Loaded(object sender, RoutedEventArgs e)
        {
            chkPrincess.IsChecked = BookData.pIsChecked;
        }

        private void chkGods_Loaded(object sender, RoutedEventArgs e)
        {
            chkGods.IsChecked = BookData.gIsChecked;
        }

        private void chkWarlords_Loaded(object sender, RoutedEventArgs e)
        {
            chkWarlords.IsChecked = BookData.wIsChecked;           
        }

        private void Princess_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Princess", UriKind.Relative));
        }

        private void Gods_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Gods", UriKind.Relative));
        }

        private void Warlords_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Warlords", UriKind.Relative));
        }

        private void myDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Book myBook = new Book();
            myBook = (Book)myDataGrid.SelectedItem;
            //MessageBox.Show(myBook.Image);
            DetailsWindows myDetailsWindow = new DetailsWindows(myBook);
            myDetailsWindow.Show();
        }
    }
}

DetailsWindow.xaml

/*** DetailsWindows.xaml ***/
<controls:ChildWindow
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:BookDataStorage="clr-namespace:Mars2.BookDataStorage" x:Class="Mars2.Views.DetailsWindows"
           Width="400" Height="300"
           Title="DetailsWindows">
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Center" Margin="0,0,0,5" Grid.Row="1" />
        <Image  x:Name="detailsImage" Source="{Binding Image_Large}" HorizontalAlignment="Left" Height="200"  VerticalAlignment="Top" Width="134" RenderTransformOrigin="0.0,0.0"/>
        <TextBlock x:Name="bookDescription" HorizontalAlignment="Left" Margin="150,5,0,0" TextWrapping="Wrap" Text="{Binding Description}" VerticalAlignment="Top"/>      
    </Grid>
</controls:ChildWindow>

DetailsWindow.xaml.cs


/*** DetailsWindows.xaml.cs ***/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Mars2.Views
{
    public partial class DetailsWindows : ChildWindow
    {
        public DetailsWindows(Book myBook)
        {
            InitializeComponent();
            detailsImage.DataContext = myBook;
            bookDescription.DataContext = myBook;
        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

Princess.xaml

/*** Princess.xaml ***/
<navigation:Page x:Class="Mars2.Views.Princess"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Princess Page">
    <Grid x:Name="LayoutRoot">
        <Viewbox>
            <StackPanel x:Name="ContentStackPanel" Orientation="Horizontal" >
                <Image Height="200" Width="134" Source="/Images/Princess_of_Mars.png" Stretch="None" HorizontalAlignment="Left"/>
                <Rectangle Width="15" />
                <ScrollViewer Height="285.49">
                <TextBlock x:Name="pTextBlock" Width="425" FontSize="11" Height="285.49"  />
                </ScrollViewer>
            </StackPanel>
        </Viewbox>      
    </Grid>
</navigation:Page>

Princess.xaml.cs

/*** Princess.xaml.cs ***/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Windows.Resources;
using System.IO;
using Mars2.BookDataStorage;

namespace Mars2.Views
{
    public partial class Princess : Page
    {
        public Princess()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Access file as Resource built into DLL
            //StreamResourceInfo sri = App.GetResourceStream(new Uri("Mars2;component/Text/PrincessOfMars2.txt", UriKind.Relative));

            // Access file as Content built in subfolder alongside DLL
            StreamResourceInfo sri = App.GetResourceStream(new Uri("Text/PrincessOfMars2.txt", UriKind.Relative));

            using (TextReader tr = new StreamReader(sri.Stream))
            {
               pTextBlock.Text = tr.ReadToEnd();
            }

            // Mark book as viewed
            BookData.pIsChecked = true;           
        }
    }
}

BookData.cs

/*** BookData.cs ***/
using System;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Mars2.BookDataStorage
{
    // Singleton for Binding to Properties
    public sealed class BookData
    {
        public static BookData _instance;
        public BookData Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new BookData();
                return _instance;
            }
        }
        public BookData() { }

        public static bool pIsChecked { get; set; }

        public static bool gIsChecked { get; set; }

        public static bool wIsChecked { get; set; }
    }
}

Book.cs

/*** Book.cs ***/
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Mars2
{
    public class Book
    {
        public string Image { get; set; }
        public string Image_Large { get; set; }
        public string Name { get; set; }       
        public string Published { get; set; }
        public string Narrator { get; set; }
        public string Description { get; set; }
    }
}


Top