Sign in to follow this  
athono

[.net] How do I tell if the browser window is Maximized in Silverlight/C#?

Recommended Posts

How do I tell if the browser window is Maximized in Silverlight/C#?

The "Form" maximize feature will not work because I am writing a silverlight app that runs in the browser.

I have tried this:

App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

but this event handler is not called when I maximize the window.

Maximized is not full screen

App.Current.Host.Content.IsFullScreen;

returns false even if I maximize the window.


Share this post


Link to post
Share on other sites
[quote name='athono' timestamp='1310693817' post='4835523']
How do I tell if the browser window is Maximized in Silverlight/C#?

The "Form" maximize feature will not work because I am writing a silverlight app that runs in the browser.

I have tried this:

App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

but this event handler is not called when I maximize the window.

Maximized is not full screen

App.Current.Host.Content.IsFullScreen;

returns false even if I maximize the window.
[/quote]

That wouldn't fire because that's server side code. Anything that is either marked as runat="server" or lives in a .cs file on the server will only impact the client if the the client has made a postback of some kind. You will likely need to hook up a page event to post back to the server and do your fullscreen check/handling there.

Share this post


Link to post
Share on other sites
[quote name='ChaosEngine' timestamp='1310943001' post='4836525']
Why do you care if the browser is maximised?Are you going to change the layout of the app if it's maximised?
[/quote]

The reason is that the layout of the app gets changed because I am unfortuantely forced to pipe my UI through a 3rd party and they seem to do wierd stuff with scaling and positioning and when the app is maximized things go flying off the right edge of the browser.

Share this post


Link to post
Share on other sites
[quote name='freddyscoming4you' timestamp='1311006282' post='4836867']
[quote name='athono' timestamp='1310693817' post='4835523']
How do I tell if the browser window is Maximized in Silverlight/C#?

The "Form" maximize feature will not work because I am writing a silverlight app that runs in the browser.

I have tried this:

App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

but this event handler is not called when I maximize the window.

Maximized is not full screen

App.Current.Host.Content.IsFullScreen;

returns false even if I maximize the window.
[/quote]

That wouldn't fire because that's server side code. Anything that is either marked as runat="server" or lives in a .cs file on the server will only impact the client if the the client has made a postback of some kind. You will likely need to hook up a page event to post back to the server and do your fullscreen check/handling there.
[/quote]



How?



By the way, how would one get the size of the desktop? That could tell me if the user has maximized the window.

Share this post


Link to post
Share on other sites
[quote name='athono' timestamp='1311012906' post='4836927']
How?
By the way, how would one get the size of the desktop? That could tell me if the user has maximized the window.
[/quote]
You could mess with the onchange event on the body tag and see if anything goes off when you size the browser. If it does, you'd sync up an AJAX call back to your site to do related functions and parse the response to perform any UI changes.

Those two sizes aren't the same. No maximized browser will tell you the size of the desktop because you have application borders from the browser, the start/task bar takes up space as well. You can use the browser info to get max screen size though. That is HttpBrowserCapabilities, in 4.0 at least.

Share this post


Link to post
Share on other sites
[quote name='athono' timestamp='1311012656' post='4836923']
[quote name='ChaosEngine' timestamp='1310943001' post='4836525']
Why do you care if the browser is maximised?Are you going to change the layout of the app if it's maximised?
[/quote]

The reason is that the layout of the app gets changed because I am unfortuantely forced to pipe my UI through a 3rd party and they seem to do wierd stuff with scaling and positioning and when the app is maximized things go flying off the right edge of the browser.
[/quote]


Basically in Silverlight, if you want a resizeable UI, you will use a [url="http://msdn.microsoft.com/en-us/library/system.windows.controls.grid%28v=vs.95%29.aspx"]grid panel[/url] to layout your controls and it will resize appropriately. It shouldn't matter if the browser window is maximised, that's just another size as far as the grid is concerned.

So the problem is most likely with "piping your ui through a 3rd party"
Can you give a bit more detail about that? sounds kinda weird.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this