Cheap Windows Hosting Tutorial – Implementing a Silverlight Based ‘Vertical’ Tickertape

ByAlexia Pamelov

Cheap Windows Hosting Tutorial – Implementing a Silverlight Based ‘Vertical’ Tickertape

5/5 - (1 vote) | Best and Cheap Silverlight hosting. In this post I will share anout implementing a silverlight Based ‘Vertical’ Tickertape.

Creating a Scrolling Region


Now to have an area of a Silverlight scroll an area, we can use the <ScrollViewer> tag. This tag is replaced around whatever mark up we want to scroll. For the news feed or this example, this will be a StackPanel, which will be orientated Vertical.

<ScrollViewer x:Name="ScrollRegion"
<StackPanel x:Name="ItemsStack" Orientation="Vertical" > 

Best and cheap SilverLight Hosting >> Click Here

The above code creates a scrollable region containing a stack with no border, white background. At the moment, the stack panel is empty – this is because the content will be added by the code behind.

Creating Our ‘Sample’ Headings

As this is an example, just to get an idea I’m not using real headlines but the Knights of the Roundtable. This is defined as an array of strings thus:

String[] Knights = { 
"King Arthur", 
"Sir Lancelot", 
"Sir Gawain", 
"Sir Geraint", 
"Sir Gareth", 
"Sir Gaheris", 
"Sir Bedivere", 
"Sir Galahad", 
"Sir Kay", 
"Sir Bors de Ganis", 
"Sir Lamorak", 
"Sir Tristan", 
"Sir Percivale"

Adding Our ‘Sample’ Headings

Adding entries to our stack panel is fairly simple. We first get a reference to the stack panel, create a textblock, set the text to our next entry and add the textblock to the Children of the StackPanel.

StackPanel sp = FindName("ItemsStack") as StackPanel;
TextBlock tb = new TextBlock();
tb.Text = Knights[0];

Setting Up the Automatic Addition of Entries

We need our application to automatically add new entries to the news feed every so often. To do this, we need something that fires after a predetermined period of time and for this, we use the DispatchTimer class.

DispatcherTimer dispatchTimer;
public Page()
dispatchTimer = new DispatcherTimer();
dispatchTimer.Interval = new TimeSpan(0, 0, 30); // 30 Seconds
dispatchTimer.Tick +=new EventHandler(dispatchTimer_Tick);

What we now need is for new headings to be added to the display each time the interval fires and for this we define a handler for the Tick event.

Adding is the same as the section above, but there are a number of additional activities that must be dealt with when adding more than the first entry. First we need to know how much space is taken up by the new heading. Once we have added the text to it, Silverlight provides the height taken up by it from the ‘ActualHeight’ property.

About the Author

Alexia Pamelov administrator

    Leave a Reply