Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / Visual Basic 10

Silverlight 3: Slideshow

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
6 Oct 2009CPOL4 min read 95K   5.4K   45   15
This is a slideshow that works in a Silverlight 3 UserControl.
Image 1

Introduction

Wow! I am so excited about sharing this Slideshow with you! Not because it’s the greatest in the world, but because it’s (not only) the first Silverlight Slideshow that I've created, but it’s also my first Silverlight user control that I've created!

But before I begin, let me show you a couple of great Silverlight Slideshows that I found:

Now, I actually tried using these slideshows before I ever decided to create my own, because they are beautiful slideshows! The only problem with them is that they have to be embedded directly in an ASP.NET webpage, which means, they cannot be embedded in a Silverlight UserControl (*.xaml). That’s frustrating! Especially if you, like me, have an entire Silverlight 3 website, and need the slideshow to be able to work in a Silverlight UserControl.

Creating a Silverlight Website

The first thing we'll do is create a Silverlight website that we can use to test our Slideshow in. So, fire up Visual Studio 2008… 

  • Click on the File menu | New | Project…

When the “New Project” window opens, perform the following actions:

  • In the Project Type TreeView, expand the Visual Basic node, then click on the Silverlight node.
  • Select the Silverlight Application from the Template ListView.
  • Make sure you have the “.NET Framework 3.5” selected. 
  • Name the project “SlideShowTest”. 
  • Click the OK button when you're ready.

Here’s what mine looks like:

Image 2

After you click the “OK” button, the following “New Silverlight Application” window will open. Just click the “OK” button to accept the default settings, and create the solution.

Download the Source Code

If you haven't done it already, download the “SlideShow Class Library” source code to your computer. The source code is in a zip file, so open the zip file and extract the SlideShow Project into the “SlideShowTest” solution folder.

Adding the Project

After you have downloaded the source code and extracted it into the solution folder, add it as a reference to your project: 

  • Click on the File menu | Add | Existing Project… 
  • When the “Add Existing Project” window opens, browse to the “SlideShowTest” solution folder, then to the “SlideShow” folder, and select “SlideShow.vbproj”.

If you've added the project successfully, then the Solution Explorer should now look like this:

Image 3

After you have added the project, you need to add a reference to it:

  • In Solution Explorer, Right-Click on the “SlideShowTest” project node, then select “Add Reference…” from the popup menu. 
  • When the “Add Reference” window opens, click the “Projects” tab, then select “SlideShow”, and click the “OK” button.

Add Your Images

Next, right-click on the “images” folder, in the SlideShow project, and select Add | Existing Item… and then add all of the images you want to view in your slideshow.

Just as a note, you don't have to add images if you don't want to. If you have the URLs to images on the web, and would like to view them in your slideshow, then you can use those URLs instead of local images. I've added several images to mine, as you can see:

Image 4

After you add your images, right-click on the SlideShowControl and select View Code. In the AddImages() method, add the URLs to your images as follows:

VB.NET
' Add the URLs of your images here.
'
' This is the only sub that you need to update.
'
Private Sub AddImages()

    'Add the images to be displayed here.
    ImageList.Add("images/Blue hills.jpg")
    ImageList.Add("images/Sunset.jpg")
    ImageList.Add("images/Water lilies.jpg")
    ImageList.Add("images/Winter.jpg")

    'You can also add URLs to images on the web
    ImageList.Add("http://tiny.cc/NX6Kv")

End Sub  'AddImages 

Adding the ContentGrid

Once you have your images in place, you are ready to add a grid to the MainPage.xaml user control in the SlideShowTest project, for hosting the Slideshow. So, double-click on the MainPage.xaml user control to open the design view. Then, drag a Grid from the ToolBox onto the XAML designer, and name it ContentGrid as follows:

XML
<Grid x:Name="LayoutRoot">
    <Grid x:Name="ContentGrid"> 
          
    </Grid> 
</Grid> 

Save and build your project.

Wiring It Up

After you've added the ContentGrid, you are ready to wire up the SlideShowControl. So, right-click on the XAML designer, and select “View Code” to open the code window.

Then, in the New() constructor method, create a new instance of the SlideShowControl, and add it to the SlideShowControl to the ContentGrid.Children collection.

VB.NET
Partial Public Class MainPage 
    Inherits UserControl
 
    Public Sub New() 
        InitializeComponent() 

        Dim ssc As New SlideShow.SlideShowControl() 
        Me.ContentGrid.Children.Add(ssc) 

    End Sub
 
End Class 

Running the Project

And that is all there is to it! Save your project, then run it (F5), and view the slideshow…

Conclusion

I really hope you find this slideshow as useful as I did. The code is easy to modify, so if you want, go in and tweak it.

Happy programming!

History

  • 6th October, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer DataPrint, LLC
United States United States

Comments and Discussions

 
QuestionRemoving the Border Pin
3d-codeaholic15-Oct-13 7:30
3d-codeaholic15-Oct-13 7:30 
QuestionOne thing missing Pin
3d-codeaholic14-Oct-13 11:54
3d-codeaholic14-Oct-13 11:54 
AnswerRe: One thing missing Pin
3d-codeaholic15-Oct-13 7:46
3d-codeaholic15-Oct-13 7:46 
GeneralNothing will be Happend Pin
shmela14-Jun-11 8:10
shmela14-Jun-11 8:10 
GeneralYour slide show project Pin
rookie12w14-Oct-10 3:01
rookie12w14-Oct-10 3:01 
GeneralVery good article for starter Pin
Anjum.Rizwi29-May-10 20:24
professionalAnjum.Rizwi29-May-10 20:24 
QuestionHow to Update the Control Pin
Lavanyaz21-Apr-10 21:05
Lavanyaz21-Apr-10 21:05 
Generalthanks Pin
cabsky13-Nov-09 7:15
cabsky13-Nov-09 7:15 
GeneralRe: thanks Pin
CS Rocks13-Nov-09 8:41
CS Rocks13-Nov-09 8:41 
GeneralRe: thanks Pin
CS Rocks13-Nov-09 8:44
CS Rocks13-Nov-09 8:44 
GeneralSilverlightfun.com Pin
Raj Lal13-Oct-09 4:12
professionalRaj Lal13-Oct-09 4:12 
GeneralVery helpful Pin
defwebserver7-Oct-09 5:10
defwebserver7-Oct-09 5:10 
GeneralRe: Very helpful Pin
CS Rocks7-Oct-09 5:12
CS Rocks7-Oct-09 5:12 
GeneralGood Job Pin
sam.hill6-Oct-09 19:11
sam.hill6-Oct-09 19:11 
GeneralRe: Good Job Pin
CS Rocks7-Oct-09 3:59
CS Rocks7-Oct-09 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.