在aspx页面中只能静态的设置Silverlight插件的大小,但是插件的高度是时常变化的,而且如果变化很大,比如从几百到几千px,那总不能一开始就设一个很大的高度吧?但问题是Silverlight并不能根据自己的高度将页面撑开,而只是clip了而已,这就带来了一个问题,如何才能在适当的时候才让浏览器的滚动条出现呢?这个问题倒是困扰了一部分的朋友的,因此来测试和总结一下。
首先建一个新工程,我这里建的是“Silverlight Navigation Application”,也就是带导航模板的,因此在模板的home.xaml页面中放一个很长的矩形,如下:
1 2 3 4 5 6 7 8 9101112 | <GrID x:name="LayoutRoot"> <!--<ScrollVIEwer x:name="PageScrollVIEwer" Style="{StaticResource PageScrollVIEwerStyle}">--> <StackPanel x:name="ContentStackPanel"> <TextBlock x:name="headerText" Style="{StaticResource headerTextStyle}" Text="Home"/> <TextBlock x:name="ContentText" Style="{StaticResource ContentTextStyle}" Text="Home page content"/> <Rectangle WIDth="200" Height="1000" Fill="Red"/> </StackPanel> <!--</ScrollVIEwer>--></GrID> |
2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132 | public MainPage(){ InitializeComponent(); this.LayoutUpdated += new EventHandler(MainPage_LayoutUpdated); } private double _minimalHeight = @H_419_146@300; voID MainPage_LayoutUpdated(object sender,EventArgs e) { Size size = this.LayoutRoot.DesiredSize; if (size.Height < _minimalHeight) { size.Height = _minimalHeight; } String heightInPixel = String.Format("{0}px",size.Height); String containerElementID = "silverlightControlHost"; @R_301_6832@Element element = @[email protected](containerElementID); element.SetStyleAttribute("height",heightInPixel);} |
2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132 | public MainPage(){ InitializeComponent(); this.LayoutUpdated += new EventHandler(MainPage_LayoutUpdated); } private double _minimalHeight = @H_419_146@300; voID MainPage_LayoutUpdated(object sender,heightInPixel);} |
2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132 | public MainPage(){ InitializeComponent(); this.LayoutUpdated += new EventHandler(MainPage_LayoutUpdated); } private double _minimalHeight = @H_419_146@300; voID MainPage_LayoutUpdated(object sender,heightInPixel);} |
以上是内存溢出为你收集整理的解决Silverlight插件过长浏览器滚动条不出现的问题全部内容,希望文章能够帮你解决解决Silverlight插件过长浏览器滚动条不出现的问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)