Tuesday, November 25, 2008

Getting browser scrollbar to scroll on silverlight content

Took me awhile to figure this one out.... probably because I didnt really understand how silverlight works. (hey, no better time to learn than when you are stuck on a problem, right?)

Problem:
The browser scrollbar doesnt appear when the silverlight control grows beyond the size of the page.

Solution:
The first point in finding the solution is realizing that the silverlight control itself resides WITHIN the asp.net control defined on your webpage and that this control's size doesnt change when the silverlight control changes. (When you first create a silverlight project, the size of the silverlight control is automatically set to 100%)

To overcome this we need to do 3 things:
  1. Remove the Height="100%" attribute from the control in your hosting asp.net page.
  2. Create a function that determines the height of all the controls within your root panel object.
  3. Utilize the HtmlElement object to set the height of your ASP.NET silverlight control

Here is how I did it:

private void UpdatePageHeight()
{
double totalHeight = 0;
foreach (RowDefinition rd in ((Grid)(Content)).RowDefinitions)
totalHeight += rd.ActualHeight;

HtmlElement he = HtmlPage.Document.GetElementById("silverlightControl");
he.SetAttribute("height", totalHeight.ToString());
}

Notes:

  • I'm using a Grid for my root panel, so I add up the height of all the rows to get my total height.
  • I call this function whenever my grid size changes.... seems to cover all cases

Monday, November 10, 2008

Setting within your httpModules removes the HttpContext







I guess this makes sense now that I blog about it.... but it really had me stuck for a few hours yesterday when I stumbled across it.
When you use the node within your httpmodules section of your web.config, it will also clear out whatever is filling the Identity.Name value as well.

I was using this setting to eliminate some errors I was getting because my application is inheriting some modules from the parent application.