Which way is up?

I have been programing for decades and fell into a rut with VBA. It was so easy to code. With the introduction of WP7 I bit the bit the bullet and took another look at C#. I had played with C when it first came out (that is the original C with no qualifiers 😉 ), but I found it almost as cryptic as APL.

With WP7 most of the examples of testing for orientation involved

if ( ( e.Orientation == PageOrientation.LandscapeRight ) || ( e.Orientation == PageOrientation.LandscapeLeft ) )
// do something for landscape orientation

Since there is no PortraitDown orientation, this could be simplied by just checking for PortraitUp. Of course, we have no guarantee that any future version of WP7 will never have a PortraitDown orientation, so we will just have to continue testing for all cases.

Today, I did come across an alternate, but because of its’ style, verges on being APL like and would need some comments.

if ( ( e.Orientation & PagePrientation.Landscape ) != 0 )
// do something for landscape orientation

this will also work…

if ( ( e.Orientation & PagePrientation.Portrait ) != 0 )
// do something for portrait orientation

Definitely something I have added to my bag of tricks. It does not matter if they introduce PortraitDown orientation.

John Marshall… Visio MVP       Visio.MVPs.org

Published by johnvisiomvp

The original Visio MVP. I have worked with the Visio team since 1993

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s