Skip to main content

Answered Question On browser window size change/Full screen changeRSS Feed

(0)

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

On browser window size change/Full screen change

Hi,

 I have an issue with the height and width of my application.

When I change the size of the browser window, say enlarge it, the application remains the size of when it was first rendered.  Say my browser window was 800x600px, when I enlarge it to 1024x768, the application remains 800x600 if i do not refresh the website.  Also, when going to fullscreen mode it does not resize to fill all the available space.

 Is there any function which i can use so that on browse window size change, it sort of refreshes/repaints the content?  How is it possible to overcome this issue?

 

Thanks

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: On browser window size change/Full screen change

Hi,

By default the behavior of Silverlight for change of size of browser window is set to fill all tab.

  
<style type="text/css">
html, body {
height: 100%;
overflow: auto;}

body {
padding: 0;
margin: 0;}

#silverlightControlHost {
height: 100%;
text-align:center;}
</style>
 
<div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
....
</div>
 

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

Blog

Twitter

Sincerely,
Sergey Lutay

jackbond
jackbond

Contributor

Contributor

2852 points

736 Posts

Re: On browser window size change/Full screen change

If you use a ScrollViewer as the root element without its width and height being set, it will expand to the size of the browser window (assuming you have set the Silverlight div to 100% as well.)

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: On browser window size change/Full screen change

Hi,

 

That is exactly how my application is set however for some funky reason its not working properly..

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: On browser window size change/Full screen change

Do you set a size inside application?

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

Blog

Twitter

Sincerely,
Sergey Lutay

Wilfred Pinto
Wilfred ...

Participant

Participant

1318 points

258 Posts

Re: Re: On browser window size change/Full screen change

A workaround using Javascript (although it will probably not work in full screen mode)!

var silverlightApp = document.getElementById("silverlightControlHost");
var parent = silverlightApp.parentNode;
parent.removeChild(silverlightApp);
parent.appendChild(silverlightApp);

See this post for more information - http://forums.silverlight.net/forums/t/88861.aspx

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: On browser window size change/Full screen change

can you tell me where I need to put this Wilfred?

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: On browser window size change/Full screen change

I only have a design width and height set, as when I set the to Auto i got an error saying that its an incorrect height/width, even though i had the mcignorable="d" (or how it is exactly..)

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: On browser window size change/Full screen change

silverlightmonster:
can you tell me where I need to put this Wilfred?

I'm not Wilfred Smile. But I think that code you should to put inside a javascript handler of onresize event of window.

 

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

Blog

Twitter

Sincerely,
Sergey Lutay

Wilfred Pinto
Wilfred ...

Participant

Participant

1318 points

258 Posts

Re: Re: Re: On browser window size change/Full screen change

Like Sergey mentioned, in the onresize javascript handler like this -

    <script type="text/javascript">
        function resize() {
            var silverlightApp = document.getElementById("silverlightControlHost");
            var parent = silverlightApp.parentNode;
            parent.removeChild(silverlightApp);
            parent.appendChild(silverlightApp);
        }
        window.onresize = resize;
    </script>

Sergey, I don't mind you masquerading as me. It makes me look good! :)

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.

jackbond
jackbond

Contributor

Contributor

2852 points

736 Posts

Answered Question

Re: Re: On browser window size change/Full screen change

Wilfred Pinto:
A workaround using Javascript (although it will probably not work in full screen mode)!

You don't need javascript to do this. For example, click the Khet link below, and view the source. No resize handlers required. All you need is a root control that stretches vertically and horizontally.

Wilfred Pinto
Wilfred ...

Participant

Participant

1318 points

258 Posts

Re: Re: On browser window size change/Full screen change

jackbond:
You don't need javascript to do this. For example, click the Khet link below, and view the source. No resize handlers required. All you need is a root control that stretches vertically and horizontally.
 

I agree! Also the javascript solution will not work in full screen mode.

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: On browser window size change/Full screen change

Hi,

 I do have a root element which stretches vertically and horizontally but its not working :(

 Im using IE8 and Vista.

jackbond
jackbond

Contributor

Contributor

2852 points

736 Posts

Re: Re: On browser window size change/Full screen change

silverlightmonster:
I do have a root element which stretches vertically and horizontally but its not working

 

Is it a Canvas?

Try making a grid the root, set its background color to something noticeable. It should fill the entire browser window if the html is correct (the default silverlight test page should work,)

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: On browser window size change/Full screen change

hi,

 

i have a scrollviewer as a root element.  It is set to stretch both vertically and horizontally and so it does when the website is loaded, however, as soon as I resize the window the application does not adjust to fill all the available space, but remains in the previous size.  The extra space is just filled with white (even the background of the application is not white!)

 

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: On browser window size change/Full screen change

Do you set a background over object tag?

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

Blog

Twitter

Sincerely,
Sergey Lutay

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: On browser window size change/Full screen change

Hi,

I just have a linear gradient, nothing fussy..

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: On browser window size change/Full screen change

If you set background over param of object tag then you will not have a white backgrdound at tab resizing.

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

Blog

Twitter

Sincerely,
Sergey Lutay

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

Hi Sergey,

I am uploading an image to help you visualise my problem.

 As you may see, the application is not filling in the browser.  First, I had the browser window that size (the application filled the whole browser size on loading), and when i enlarged it, the application did not resize to fill the enlarged window but remained the same size.

 

Height and Width issue

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

It is so because you use a ScrollViewer control as a root element for layout.

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

Blog

Twitter

Sincerely,
Sergey Lutay

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

You need to subscribe to javascript onresize event and set size of ScrollViewer programmatically.

It you set height and width properties of ScrollViewer then try to set them to empty or Auto value.

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

Blog

Twitter

Sincerely,
Sergey Lutay

silverlightmonster
silverli...

Member

Member

17 points

100 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

How is that possible?  How can i do that?

 

If i put a canvas as the root element and set it to stretch it should work?

Sergey.Lutay
Sergey.L...

Star

Star

8374 points

1,526 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

silverlightmonster:
How is that possible?  How can i do that?

 

public MainPage()
{
	InitializeComponent();
	Loaded += new RoutedEventHandler(MainPage_Loaded);
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
	HtmlPage.Window.AttachEvent("onresize", OnWindowResize);
}

void OnWindowResize(object sender, HtmlEventArgs e)
{
	var height = HtmlPage.Document.Body.GetProperty("clientHeight");
	var width = HtmlPage.Document.Body.GetProperty("clientWidth");
}

 

silverlightmonster:
If i put a canvas as the root element and set it to stretch it should work?

Better use a Grid.

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

Blog

Twitter

Sincerely,
Sergey Lutay

jackbond
jackbond

Contributor

Contributor

2852 points

736 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

Sergey.Lutay:
You need to subscribe to javascript onresize event and set size of ScrollViewer programmatically.

 

OK, here goes, and hopefully for the last time:

YOU DO NOT NEED TO **** WITH ANY JAVASCRIPT EVENTS TO FILL THE ****** SCREEN

Take the following code and put in your XAP file name

 

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Blazing7s</title>
    <style type="text/css">
    html, body {
	    height: 100%;
	    overflow: auto;
    }
    body {
	    padding: 0;
	    margin: 0;
    }
    #silverlightControlHost {
	    height: 100%;
	    text-align:center;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }
            
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {           
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
		  <param name="source" value="YOUR_FILENAME_HERE.xap"/>
		  <param name="onError" value="onSilverlightError" />
		  <param name="background" value="white" />
		  <param name="minRuntimeVersion" value="3.0.40818.0" />
		  <param name="autoUpgrade" value="true" />
		  <param name="MaxFrameRate" value="30" />
		  <param name="enableGPUAcceleration" value="true" />
		  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
 			  <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
		  </a>
	    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>
</body>
</html>
  

Wilfred Pinto
Wilfred ...

Participant

Participant

1318 points

258 Posts

Re: Re: Re: Re: On browser window size change/Full screen change

You are probably just doing something wrong. If you post your project here I am sure someone will be able to spot it right away.

I implemented a photo viewer some time ago which handles browser resizing properly. I even did content resizing to avoid clipping as far as I could. You can find a sample here - http://thepintospatronus.com/simpleviewer-sl/gallery1/gallery2.html. The source code can be found here - http://simpleviewersl.codeplex.com/

There is a lot of (not relevant to you) code in there so it probably is overkill for your case. It would be better if you just post a scaled down version of your project here.

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.
  • Unanswered Question
  • Answered Question
  • Announcement