Turn the page !

by gleblanc 29. September 2008 19:24

!!!!!!! This page has been updated for Silverlight 2 RTM : see post of Nov 18th (http://www.gleblanc.eu/Blog/post/Page-turner-updated-for-Silverlight-2-TRM.aspx)  !!!!! 

In this post, we'll turn pages, thanks to an outstanding component developed and made freely available by Mitsu Furuta of Microsoft France.

Turn the pages using the mouse, as if it was a book ! There are five paintings of Brueghel (a painter of 16th century) to be seen.
 


Project / source code 

To add such a "page turner" into your Silverlight program, download the DLL that does the job. First, access the project on Codeplex. The component was developed by Mitsu Furuta of Microsoft France. Incidentally, Mitsu is blogging in French but also in English.

Download the zip file, unzip it, compile the project in the SLBookDemoApp directory and extract the SLMitsuControls.dll file that is created by the compiler in the ClientBin sub-directory.

The use of this component is under "Microsoft Public License" (MS-PL). I can read a computer book as if it was a novel but reading just a few paragraphs of lawyer's jargon always gives me headache. But here it's rather clear : you can use the component "as it is", even in commercial applications, royalty-free (I mean the component described here is royalty-free, not necessarily your application). Of course, you can't claim rights on this component... For me, it was obvious. Programmers and lawyers seem to have a brain somewhat different. 

In your application, add a reference to the DLL you have just extracted and saved somewhere. In the UserControl tag in the xaml file, add :
 xmlns:local="clr-namespace:SLMitsuControls;assembly=SLMitsuControls"
I chose local for future reference to the component but any name could be chosen.

Now, you need to add a component that has a visual appearence :
 <local:UCBook x:Name="book" ..... />
where ..... can be replaced by any property you usually find in a component (Grid.Row, Canvas.Left, etc.).

Now, let's see the changes that have to be made in your Page.xaml.cs file. Your Page class must implement the IDataProvider interface (and consequently implement GetItem and GetCount functions). Some initialization (one line) has also to be done in the function that handles the Loaded event :
 using SLMitsuControls;
 .....
 public partial class Page : UserControl,IDataProvider
 {
  .....
  private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
  {
   book.SetData(this);
  }
  public object GetItem(int index)
  {
   return pages.Items[index];
  }
  public int GetCount()
  {
   return pages.Items.Count;
  }
  .....
 }

The images (here five) have to be mentionned in Grid.Resources (or Canvas.Resources, depending on the container) :
 <Grid .... >
  <Grid.Resources>
  <ItemsControl x:Name="pages" >
   <Image Source="Brueghel1.jpg" Stretch="UniformToFill"  />
   <Image Source="Brueghel2.jpg" Stretch="UniformToFill"    />
   <Image Source="Brueghel3.jpg" Stretch="UniformToFill" />
   <Image Source="Brueghel4.jpg" Stretch="UniformToFill"   />
   <Image Source="Brueghel5.jpg" Stretch="UniformToFill"  />
  </ItemsControl>
 </Grid.Resources>
 ....
 </Grid>

The images (here 5 images, from Brueghel1.jpg to Brueghel5.jpg) need to be copied in the ClientBin directory (the directory of the xap file). This is often an overlooked step : adding the images in the project (as often done for images) doesn't help. The images need to be explicitly copied into the ClientBin directory. 

To know which pages are visible, just handle the OnPageTurned event :
 <local:UCBook x:Name="book" ..... OnPageTurned="book_OnPageTurned" />
 .....
 private void book_OnPageTurned(int leftPageIndex, int rightPageIndex)
 {
  .....
 }

The leftPageIndex and rightPageIndex arguments get the value -1 when a page is not displayed (for instance there is no page at the left when the book is initially opened).

A page is not restricted to images : it could contain a set of components. Just replace the <Image ..... /> tag by any other tag, for instance a grid tag (container for all the elements of a page).  

Tags:

Comments

10/1/2008 8:32:52 AM #

Trackback from Community Blogs

Silverlight Cream for September 30, 2008 -- #383

Community Blogs

10/1/2008 6:57:55 PM #

Pingback from mgalinks.wordpress.com

2008 October 01 - Links for today « My (almost) Daily Links

mgalinks.wordpress.com

12/15/2008 7:11:42 AM #

Good info.

busby seo test United States

1/20/2009 5:47:23 PM #

Thank for the step tutorial.

Busby Seo Test United States

2/22/2009 8:26:56 AM #

Very entertaining Site. I'd have to say nice article if i do say so myself. nice site. I hope you don't mind I've put you in my rss feed now. I'm excited and look forward to your Updates.

Auctions Directory United States

2/25/2009 7:10:07 AM #

Microsoft's silverlight technology will engage the average corporate Web developer more than ever before when it comes to creating rich, animated online content and applications, the CRN Test Center believes. Silverlight sports a simple framework, built purely on XML and .Net, that stands to significantly ease Web design and development.

Unusual Gifts United States

2/26/2009 7:12:20 AM #

Great Tutorial on silverlight thanks in advance!

XOXO
Tiffany

Wigs United States

3/13/2009 7:58:43 AM #

Great tutorial thanks for sharing very useful.

Hectic Capiznon Bloggers 2009 Republic of the Philippines

3/25/2009 4:39:08 PM #

Informative tutorial. Thanks for the info. it is very great in animated sites.

James Capiznon Republic of the Philippines

6/24/2009 6:05:41 PM #

Thanks for walking us through the installation of silverlight!

Oakland Personal Injury on Bicycle Lawyer United States

6/29/2009 8:40:29 AM #

I'm working on looking and searching for the problems or errors of different blogengine to prevent problems or errors in my blog site and also to know the solution to fix different problems or errors about this matter.

California Orange Country Lawyer United States

7/4/2009 10:23:48 PM #

thank for sharing this one , this will be a great news

California Orange County Lawyer United States

7/8/2009 9:32:38 PM #

What a nice information. It is very useful and interesting. Thanks for the codes.

pinay United States

7/9/2009 7:37:44 AM #

This is a very well written article.Easy to follow.

club penguin cheats United States

7/14/2009 3:05:25 PM #

I don't like your template but your posts are quite good so I will check back!

Adee Kaye United States

7/22/2009 10:16:06 AM #

A programmer is someone who writes computer software. While a lawyer is a person learned in the law; as an attorney, counsel or solicitor; a person licensed to practice law.

California Criminal Defense Attorney United States

7/22/2009 10:48:44 PM #

nice!

Jm-Experts United States

7/24/2009 9:27:02 PM #

Hey I love your style I will subscribe for your feed please keep posting!

Jacques Lemans United States

8/5/2009 6:46:10 AM #

Hello to all Smile I can�t understand how to add your site in my rss reader. Help me, please

payday loans United States

8/5/2009 6:46:13 AM #

There is obviously a lot to know about this.  I think you made some good points in Features also.

payday loans United States

8/14/2009 7:12:35 PM #

Very nice piece on silverlight i cant wait to use this in my next .net project

sports gifts United Kingdom

8/15/2009 12:31:17 AM #

Come on dude, these facts* and proof* i mean who is posting* lol Tong

payday loan United States

8/15/2009 12:31:21 AM #

Hi there, I found your blog via Google while searching for first aid for a heart attack and your post looks very interesting for me.

payday loan United States

8/20/2009 2:19:48 PM #

Thanks for sharing your views on the topic. It makes one think and look the other side of the story.

Home Condition Reports United Kingdom

8/31/2009 11:07:41 AM #

Hi,
Antivirus software heavily relied upon signatures to identify malware. This can be very effective, but cannot defend against malware unless samples have already been obtained and signatures created. Because of this, signature-based approaches are not effective against new, unknown viruses.

spyware removal United States

8/31/2009 11:08:28 AM #

Hi,


How a software can detect that my internet transaction is secure n can not be hacked ?

Antivirus software United States

9/10/2009 4:13:19 PM #

I wanted to thank you for this great read!! I definitely enjoying every little bit of it Smile I have you bookmarked to check out new stuff you post.

Divorce Attorney Memphis United States

9/12/2009 12:22:29 PM #

We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on. You have done a marvellous job!

payday online United States

9/13/2009 5:15:39 PM #

Toto ozn�men� o stavu doru.en� je generov�no automaticky.

cash loans United States

9/13/2009 9:33:01 PM #

I believe this aspect is growing everywhere as business owners learn what it is. For example, Phoenix is much more sophisticated in this regards than here in Tucson. I average small business owner is still way behind in their understanding such incidents.

annuity quotes United States

9/14/2009 9:34:04 AM #

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts.Any way Ill be subscribing to your feed and I hope you post again soon

payday loans United States

9/22/2009 3:55:59 PM #

Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such informat

Orlando personal injury lawyers United States

9/24/2009 3:51:05 AM #

good good�this post deserves nothing Frown  �hahaha just joking Tong �nice post Tong

payday loan United States

9/24/2009 3:51:11 AM #

my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with �we leave it to you to decide�.

payday loan United States

9/24/2009 7:06:47 AM #

Blogroll links aint that great Tong but i am not the admin� Tong � Just Telling Tong Laughing

bad credit loans United States

9/24/2009 7:06:52 AM #

You made some good points there. I did a search on the topic and found most people will agree with your blog.

bad credit loans United States

9/28/2009 7:27:12 PM #

Having read all the post I totally recognize all the points are true.

La web developer United Kingdom

9/29/2009 9:22:27 AM #

Great overview. Your style of writing is really a joy to read.

Make Money Online United States

9/30/2009 11:34:17 AM #

Pingback from mgalinks.wordpress.com

2008 October 01 - Links for today « My (almost) Daily Links

Tiffany Rings People's Republic of China

10/1/2009 1:42:47 PM #

great job, thanks

outdoor fireplace brick oven United States

10/2/2009 4:15:27 PM #

That�s Too nice, when it comes in india hope it can make a Rocking place for youngster.. hope that come true.

personal loan United States

10/2/2009 4:15:30 PM #

Super-Duper site! I am loving it!! Will come back again - taking you feeds also, Thanks.

personal loan United States

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Gerard Leblanc is the author of several books (in french) on C++, C#, .NET and Silverlight (Eyrolles, Paris as publisher). See www.gleblanc.eu as the companion web site for these books (included sample programs).
He is Microsoft MVP for Silverlight.

MVP logo