设法弄清楚滚动条发生了什么。
BrowserScrollHelper 中用于将 silverlight 控件的大小传回浏览器的代码正在使用以下代码:
double clientWidth = BrowserScreenInformation.ClientWidth;
double clientHeight = BrowserScreenInformation.ClientHeight;
double width = Math.Max( clientWidth, this.MinWidth );
double height = Math.Max( clientHeight, this.MinHeight );
htmlElement.SetStyleAttribute( "height", height.ToString( ) );
htmlElement.SetStyleAttribute( "width", width.ToString( ) );
虽然这段代码 sn-p 在表面上看起来不错,但它只是完成了部分工作。关键是要意识到设置高度可能会影响宽度,反之亦然,而且我们只在应用程序启动时运行过这段代码。
解决方案是遵循以下任一模式:
设置高度、设置宽度、设置高度
或
设置宽度、设置高度、设置宽度
这确保了通过代码的单次传递将正确地将silverlight控件的大小传回给浏览器,使其有机会正确获取垂直和水平滚动条。
工作代码如下所示:
double clientHeight = BrowserScreenInformation.ClientHeight;
double height = Math.Max( clientHeight, this.MinHeight );
htmlElement.SetStyleAttribute( "height", height.ToString( ) );
double clientWidth = BrowserScreenInformation.ClientWidth;
double width = Math.Max( clientWidth, this.MinWidth );
htmlElement.SetStyleAttribute( "width", width.ToString( ) );
clientHeight = BrowserScreenInformation.ClientHeight;
height = Math.Max( clientHeight, this.MinHeight );
htmlElement.SetStyleAttribute( "height", height.ToString( ) );
在我们的例子中,最终用户很可能会启动最大化的浏览器,并在整个会话期间将其保留在该配置中,并且不执行任何浏览器窗口大小的调整。