Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to specify the height and width of Canvas by perce... RSS

10 replies

Last post Jan 09, 2008 02:38 AM by mchlsync

(0)
  • mchlSync

    mchlSync

    Star

    14968 Points

    2799 Posts

    Re: How to specify the height and width of Canvas by percentage.?

    Jan 09, 2008 02:38 AM | LINK

    Try the following steps ~

    1. Set [Scriptable] in Page.xaml

    2. Add the constructor in Page.xaml

    public Page()
            {
                try
                {
                    WebApplication.Current.RegisterScriptableObject ("EntryPoint", this);
                }
                catch ( Exception ex )
                {

                }
             
            }

    3. Update this function in TestPage.html.js. (Take a look at bold)

    document.body.onload = function() {
          var silverlightControl = document.getElementById('SilverlightControl');
          if (silverlightControl)
             silverlightControl.focus();
        
          var control = document.getElementById("SilverlightControl");
          control.Content.EntryPoint.InitResolution(screen.width, screen.height);  
       
       
        } 

     4. Add this function in Page.xaml

    double _width;
            double _height;

            [Scriptable]
            public void InitResolution(string width,string height)
            {
                _width =  Convert.ToDouble(width);
                _height =  Convert.ToDouble(height);
                this.SetValue (WidthProperty, _width);
            }

     

    then, it will work.  

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net