Thursday, November 20, 2008
Trusted by over 7 million customers!
Silverlight Scroll Bars - Version 1
Minimize
Location: BlogsSilverlight Code & Controls   
Posted by: Ken Dopierala Jr.9/25/2007 4:39 PM
Silverlight Scroll Bars Control - Version 1 - RTLStandardScoll Vertical Scrollbars for a canvas that contains a TextBlock. The scroll bar sizes itself and can be added with only 1 line of XAML. While working on a recent Silverlight project I found it necessary to have scroll bars for some of our TextBlocks that had changing text lengths. I found a few options on the web but nothing that I wanted to implement on a consistent basis. What I really needed was a solution that would allow me to attach a set of Vertical Scroll Bars quickly and without the hassle of sizing or calculating scroll increments each time. The solution I came up with was to create a custom control for Silverlight using managed code. The control requires only one line of XAML to use:

While working on a recent Silverlight project I found it necessary to have scroll bars for some of our TextBlocks that had changing text lengths.  I found a few options on the web but nothing that I wanted to implement on a consistent basis.  What I really needed was a solution that would allow me to attach a set of Vertical Scroll Bars quickly and without the hassle of sizing or calculating scroll increments each time.

The solution I came up with was to create a custom control for Silverlight using managed code.  The control requires only one line of XAML to use:

<RTL:RTLStandardScroll_V1 x:Name="scBar" Canvas.Top="20" Canvas.Left="20" ButtonColor="#FFFFFF" GripColor="#111111" ArrowColor="#000000" TrackColor="#CCCCCC" ScrollObject="cvsTheText" />

The Canvas.Top, Canvas.Left properties are ignored (they are generated automatically by the control).  The color properties let me set the colors quickly and the ScrollObject is the name of the TextBlock to scroll.  The TextBlock but be contained inside of a Canvas.  That Canvas should start with 2 children.  The first is a Canvas.Clip and the second is the TextBlock.

That is all there is to it.

You can view a demo and download the source here: http://www.RealTimeSilverlight.com

RTL Standard Scrollbar V1 Screen Shot

The next version will include support for Horizontal scrolling.

Currently the colors must be set using a six-digit Hex value.

If you have any questions or suggestions for future versions feel free to contact me.

 

Copyright ©2007 Ken Dopierala Jr.
Permalink | Trackback

Comments (6)  Add Comment
Re: Silverlight Scroll Bars - Version 1  By dressder on 9/26/2007 2:22 PM
when will you have horizontal support? can i use the bar by itself as a slider or use javascript to capture when it moves? i like it otherwise, it feels nice to use it really smooth. dressder

Re: Silverlight Scroll Bars - Version 1  By Jim on 9/26/2007 10:31 PM
Why are you using a storyboard? You forgot to mention that you have to add a reference to the control if you want it to work. I can use your control if I use it like in your example code but I can't change it much without it breaking. Could you make a better example with thinner code. I don't need a storyboard! And I would like it scroll much faster. Thansk! Don't forget to post code with the fixed update.

Re: Silverlight Scroll Bars - Version 1  By RadiateLogic on 10/1/2007 10:05 PM
Dressder - Horizontal support will be release tomorrow. I've thought about turning it into a slider but haven't yet. The beginning of Javascript support is in there, I just need to tie up a few loose ends for enabling JS client scripting. --- Ken

Re: Silverlight Scroll Bars - Version 1  By RadiateLogic on 10/1/2007 10:05 PM
Jim - I use the storyboard as a timer. Currently the timer object isn't operational, hopefully it will be soon! The scroll speed is as fast as it can really get, the only other way is to make the incremental jumps bigger but that would result in a choppy scrolling experience. I'm not sure I follow you on the reference requirement, send me a code example and I'll take a look. --- Ken

Re: Silverlight Scroll Bars - Version 1  By Michael Kariv on 11/21/2007 11:17 PM
I have ported your code to C# and I made it to scroll any FrameworkElement, not just textbox. <br>If you're interested I can send it to you.<br>

Silverlight Scroll Bars - Version 1  By Ravi on 5/21/2008 5:00 AM
Sir...My problem is i am using an canvas in silverlight...and zooming functionality on canvas....i want when i zoom in canvas using mouse wheel...so does it calculate the size of horizental and vertical scrollbars so that user can scroll and view entired zoomed canvas.....plz help me....


Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
Nationwide Freight Trucks - Reefer - Expedited - LTL - Truck Load - Brokerage

Free Online Dating Coupons (Match.Com, Date, PerfectMatch, Lavalife and More)



Blog_Archive
Minimize

Print  

Nationwide Building Permits - Courier Services - Expedited Permits - Retail Construction Permits

Who is looking for you online?
Find out now....


Click Here to get 1 month FREE Dedicated Hosting
Trusted by over 7 million customers!

Privacy Statement  |  Terms Of Use
Copyright 2007 by RTLogicSystems.Com