Professional, Software

Fixes for Sample ScrollViewer

I was trying to use Sample ScrollViewer shipped as part of Controls sample pack in SDK for Silverlight Alpha 1.1. There are few bugs that I thought people will come across…

Clipping issue

Same as ListBox Clipping Issue, Control seems to set the clip on the wrong object. Fix is also the same.

In the UpdateLayout method, you need to change following line…

Clip = clip;

to

ActualControl.Clip = clip;

ScrollViewer.Content is not initialized

ScrollViewer.Content property is not initialized. So if you try to add children to Content, it will throw an exception. so when you use ScrollViewer, you need to initialize it. Instead of fixing this in control, i just fixed the code where i need to use ScrollViewer.

so constructor for the control that uses ScrollViewer looks like this…

scrollviewer = rootCanvas.FindName("scrollviewer") as ScrollViewer; 
scrollviewer.Content = new Canvas();

ValueRange is not set at UpdateLayout time

ValueRange is only set when the content property is set. But Content height and width can change and so should range property. So I copied following piece of code from Setter of content property to UpdateLayout function. This means that I need to set the height/width of content before I set height/width of ScrollViewer because that is when UpdateLayout gets called.

if (horizontalScrollBar != null) 
{ 
    horizontalScrollBar.Range = new ValueRange(0, content.Width); 
} 
if (verticalScrollBar != null) 
{ 
    verticalScrollBar.Range = new ValueRange(0, content.Height); 
} 

So my app code looks like this…

scrollviewer.Content.Height = ItemHeight * _numberOfRows; 
scrollviewer.Height = Height;
scrollviewer.Content.Width = ItemWidth * _numberOfColumns; 
scrollviewer.Width = Width;
Standard

4 thoughts on “Fixes for Sample ScrollViewer

  1. Pingback: Recursive Reflection : Fixes for Sample ScrollViewer Control

  2. Pingback: Part 4: Search Application (Search Result View) « Desperately Seeking Love of Sophie

  3. Great goods from you, man. I’ve understand your stuff previous to and you’re just too wonderful. I actually like what you have acquired here, certainly like what you’re stating and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I can not wait to read far more from you. This is really a terrific site.

Leave a comment