Scrollable Stack Panel In Silverlight 3 Using Blend 3

No.of Views1269
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  16 Feb 2010 00:02:01
Tag : Silver Light and XAML , How to
Scrollable Stack Panel In Silverlight 3 Using Blend 3
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 Introduction
In this article we will see how we can make a Stack Panel Scrollable. That means when there are many Children of a Stack Panel how can we see it while scrolling.


Creating Silverlight Project
Fire up Blend 3 and create a Silverlight Application. Name it as ScrollableStackPanelInSL3.

Image Loading....


Here is the basic idea what we will do: we will add a Scroll Viewer to the Application and add a Stack Panel and we will see how changing some properties will give us a Scrollable Stack Panel.
Go ahead and draw a Scroll Viewer. You can find it in the Asset Library.

Image Loading....


After adding and giving it a width and height you will find that the default Scroll Bar is Vertical.

Image Loading....

For our requirement we will make it as Horizontal. Just change the below properties and you are done with Scroll Viewer.

Image Loading....

You can see from the above figure; that I have Disabled the Vertical Scroll Bar and made Auto for the Horizontal Scroll Bar.
Now add a Stack Panel into the Scroll Viewer name it as MyStackPanel.

Image Loading....

Now I have changed some properties like Horizontal Alignment to Left and the most important property I have changed is the Width property. I have made it Auto.

Image Loading...

Now add a Button to the Application and name it as btnAddItem.

Image Loading....

In the Button’s Click event Handler we will add the following code:
{codecitation class="brush: csharp; gutter: true;" width="700px"}

private void btnAddItem_Click(object sender, RoutedEventArgs e)
{
MyStackPanel.Children.Add(AddItems());
}

private Button AddItems()
{
Button btn = new Button();
btn.Width = 150;
btn.Height = 100;
btn.Content = "Button";

return btn;
}

{/codecitation}

In the above code I am adding a Button. Now if you will run your application and add some items to the Stack Panel; you will see when it reaches out of the view the Scroll Viewer’s Horizontal Scroll is activated. And if you will scroll right you will find the items you added.

Image Loading....

That’s it we have successfully achieved Scrolling for a Stack Panel.
Enjoy Coding.


About the Author


Diptimaya Patra

Description :I am a Master in Computer Application (MCA) from SRM University, Chennai. I am MCTS in ASP.Net Web Development, and MOSS 2007 Administration. I have extreme exposure to Microsoft Technologies in recent times like Silverlight 2, Silverlight 3. I am from Cuttack, Orissa. You can reach me using this mail (diptimaya.patra@gmail.com). Currently I am working as a Software Engineer in UST Global Inc in Trivandrum Center.

Occupation :Software Engineer
Company : UST Global.
Location : India
Follow me at twitter : http://twitter.com/dpatra


 
Sign Up to vote for this article
 
About Author
 
dpatra
Occupation-Not Provided
Company-Not Provided
Member Type-Expert
Location-Not Provided
Joined date-13 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top