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

Started by
5 comments, last by ChaosEngine 12 years, 9 months ago
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.


Advertisement
Why do you care if the browser is maximised?Are you going to change the layout of the app if it's maximised?
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

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.


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.

Why do you care if the browser is maximised?Are you going to change the layout of the app if it's maximised?


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 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.


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.

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

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.

[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?


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 grid panel 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.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

This topic is closed to new replies.

Advertisement