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'
d:DesignWidth='640'
d:DesignHeight='480'>
//File:Page.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.ComponentModel;
using System.Collections;
using System.Collections.Generic;
namespace SilverlightApplication3
{
public class Book : INotifyPropertyChanged
{
private string bookTitle;
private string bookAuthor;
private int quantityOnHand;
private bool? multipleAuthor;
private string authorURL;
private string authorWebPage;
private List myChapters;
public event PropertyChangedEventHandler PropertyChanged;
public string Title
{
get { return bookTitle; }
set
{
bookTitle = value;
NotifyPropertyChanged( "Title" );
}
}
public string Author
{
get { return bookAuthor; }
set {
bookAuthor = value;
NotifyPropertyChanged( "Author" );
}
}
public List Chapters
{
get { return myChapters; }
set {
myChapters = value;
NotifyPropertyChanged( "Chapters" );
}
}
public bool? MultipleAuthor
{
get { return multipleAuthor; }
set {
multipleAuthor = value;
NotifyPropertyChanged( "MultipleAuthor" );
}
}
public int QuantityOnHand
{
get { return quantityOnHand; }
set {
quantityOnHand = value;
NotifyPropertyChanged( "QuantityOnHand" );
}
}
public void NotifyPropertyChanged( string propertyName )
{
if ( PropertyChanged != null )
{
PropertyChanged( this,
new PropertyChangedEventArgs( propertyName ) );
}
}
}
public partial class MainPage : UserControl
{
private Book b1;
private Book b2;
private Book currentBook;
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler( Page_Loaded );
}
void Page_Loaded( object sender,RoutedEventArgs e )
{
Change.Click += new RoutedEventHandler( Change_Click );
b1 = new Book();
InitBookB( b1 );
currentBook = b2 = new Book();
InitBookA( b2 );
SetDataSource();
}
private void InitBookA( Book b )
{
b.Title = "A";
b.Author = "B";
b.MultipleAuthor = true;
b.QuantityOnHand = 20;
b.Chapters = new List() { "A", "Controls", "Events", "Styles" };
}
private void InitBookB( Book b )
{
b.Title = "Bleak House";
b.Author = "Charles Dickens";
b.MultipleAuthor = false;
b.QuantityOnHand = 150;
b.Chapters = new List(){"1", "2", "3" };
}
void Change_Click( object sender, RoutedEventArgs e )
{
if ( currentBook == b1 )
currentBook = b2;
else
currentBook = b1;
SetDataSource();
}
void SetDataSource()
{
LayoutRoot.DataContext = currentBook;
}
}
}