Silverlight-daily construction plan report (4)-adaptive browser window

Source: Internet
Author: User

From http://www.cnblogs.com/codelove/archive/2011/06/12/2079232.html

In many cases, from the perspective of user experience, we want our Silverlight Program It can adapt to various browser windows or frameworks ,:

So how can the Silverlight program adapt the size of the browser window, even when the browser window is dynamically changed. After several times of Google, I did not find the solution I needed, so I had to solve it myself.

First, is there a way to program in SilverlightCodeTo get the height and width of the browser? This does not seem to work out. application. Current. Host. content. actualwidth and application. Current. Host. content. actualheight obtain the height and width of the plug-in. The browserinformation object obtains information from the browser, but does not have a high width. So it is feasible to use js to obtain the browser width.

How can I make the program adaptive when I get the browser's height and width? So I thought of the "window. onresize" event. In this way, the problem is solved. The specific code is as follows:

First, the following methods are defined in Silverlight:

?
123456789101112131415161718 /// <Summary> /// Set the control layout (based on the window) /// </Summary> [Scriptablemember ()] Public Void Setlayout ( String _ Winwidth, String _ Winheight) { Double _ Required wwidth = convert. todouble (_ winwidth ); Double _ Required wheight = convert. todouble (_ winheight ); // Set the scroll box width Svplans. width = _ Your wwidth-8; Canvas. setleft (spbuttons, _ blank wwidth-400 ); Canvas. setleft (txttitle, _ blank wwidth/2-150 ); Canvas. setzindex (cvshowprocess, 999 ); Canvas. setleft (cvshowprocess, _ 1_wwidth/3 ); Canvas. settop (cvshowprocess, 80 ); // Set the height of the scroll box Svplans. maxheight = _ running wheight-54; }

This function can be called using Js. As described in the previous article, it is skipped. After writing the layout method, it is time to write js to call it. Usercontrol_loaded

The event is hard, and the following code is written in it:

?
123456789 // JS calls the setlayout function to set the control layout Htmlpage. Window. eval ( @" SetTimeout ( Function () implements slctl.content.planview.setlayout(document.doc umentelement. clientwidth, document.doc umentelement. clientheight ); Window. onresize = function (){ Slctl.content.planview.setlayout(document.doc umentelement. clientwidth, document.doc umentelement. clientheight ); } }, 1000 );" );

In this way, both the first loading and the "window. onresize" event can call the previous layout method to implement adaptive browser window. The above code is worth noting that "slctl. content. the planview object of planview has mentioned how to register in Silverlight in the previous article. If you do not understand it, please read Silverlight-daily construction plan report (3 ).

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.