Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 Silverlight App Scalability Scalability

I'm writing a number of WP7 apps right now that need absolute sizing, depending on display device. What this means that the app size needs to be 656 (w) by 480 (h), which is perfect for WP7 with both shell:SystemTray.IsVisible="True" and shell:ApplicationBar IsVisible="True". From a possible 800 x 480, both those bars used take 144, so I'm good on that front.

On a PC, I'd use a larger version of that size need, like 720x540.

However, if iPhone->iPad is any indication of possible revenue streams for MSFT (as well as Ballmer re-investing in the tablet business), I'm going to make the assumption that we'll see a tablet-sized unit come out soon enough for the WP7 OS.

Also, there may be a 400x240 resolution of WP7 to come out.

What I'd like is for my apps to be immediately available to different sized devices, based on those dimensions above (656 (w) by 480 (h), or a scaled version of that) - rather than having to just change a single set of values to re-release an app. Note: I don't use a <Grid/> or <StackPanel/> - and I can't. Every single thing in the app is absolutely positioned and this is on purpose.

So the question here is - is there some value that I can read about the screen resolution size of the device my app is running on? I've looked through the reference, but couldn't find anything like this.

like image 572
Todd Main Avatar asked Aug 12 '10 05:08

Todd Main


2 Answers

You can determine the available display size with:-

var width = Application.Current.Host.Content.ActualWidth;
var height = Application.Current.Host.Content.ActualHeight;

These remain the same despite the orientation. Using the dimensions of the RootVisual would probably work as well but if for bizare reason the RootVisual has a fixed size then that won't work.

The ActualWidth and ActualHeight properties above are designed specifically to inform the application of the size of viewport being provided by the host device.

like image 126
AnthonyWJones Avatar answered Oct 19 '22 15:10

AnthonyWJones


From what I hear, tablet (slate) style devices will run a full version of Windows 7 (not Windows Phone 7) but with an addtional software layer on top for better/simpler/easier use in the slate context.

WP7 devices will be coming out with HVGA screens (480x320) and Microsoft have explicitly stated that there won't be any other sizes in the future. (They've learnt the lesson of trying to support multiple screen sizes.) This means that you won't need to worry about 400x240.

In answer to your actual question:
You can get the size of the screen by accessing the RenderSize of the RootVisual, like so:

var size = App.Current.RootVisual.RenderSize;

var msg = string.Format("Height: {0}\r\nWidth: {1}", size.Height, size.Width);

MessageBox.Show(msg, "size", MessageBoxButton.OK);

If the device is rotated it still gives the dimensions from a portrait orientation.

Please note. This is based on my tests in the emulator & not tested on different devices with different size screens.

like image 25
Matt Lacey Avatar answered Oct 19 '22 14:10

Matt Lacey