Microsoft Surface is designed to allow MultiUser and MultiTouch interaction.While MultiTouch is easy to acknowledge, the MultiUser and designing a smart changing of Surface’s screen orientation is a little difficult coming from desktop computing, where the monitor’s down will be the same always.
In order to understand the need of changing the screen orientation on a Microsoft Surface, you might want to think about it’s normal usage: Collaboration and User experience. In the implementation for a group of 4-8 people, sitting around the Surface, their need for rotating the environment is almost zero or otherwise they will experience dizziness and losing their focus while rotating the environment for one of them.
While for the situation in which you have casual visitors(as in BMW implementation in their showrooms), who sit in pairs working on one Surface, you might considering rotating the window such that the ‘Down’ of the application would be the nearest edge to them.
The Microsoft Surface SDK provides such ways that not only you know where the users are (by reading the direction from their fingers hit area) but also to rotate the application on screen.
One of the easiest checks that can be made are verifying the static property Microsoft.Surface.ApplicationLauncher.Orientation.In order to be automatically noticed, there is an event published by the framework: Microsoft.Surface.ApplicationLauncher.OrientationChanged. It fires when the user changes his side by touching on the access buttons at the corresponding side.
But let’s better dig into some code.
The rotating of screen is done through a RotateTransform, transformation known very well from Computer Graphics. We’ll apply this transformation with a computed Angle according to the Orientation. In order to apply this to the main application window, we will set the RotateTransform in the root element of the SurfaceWindow.
<s:SurfaceWindow x:Class="SurfaceApplication1.SurfaceWindow1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="http://schemas.microsoft.com/surface/2008" Title="SurfaceApplication1"> <Grid Name="MenuGrid"> <Grid.LayoutTransform> <RotateTransform x:Name="OrientationTransform" Angle="0"/> </Grid.LayoutTransform> <TextBlock Name="OrientationTextBox" HorizontalAlignment="Center"/> </Grid> </s:SurfaceWindow>
Since for this small example we’re interested only to setup the orientation at the startup of the application, all we need is to subscribe to be notified by the event loop on the ApplicationLauncher.OrientationChanged event. Thus, we’ll set the Angle as per the ApplicationLauncher.Orientation property.
private void AddActivationHandlers() { // Subscribe to surface application activation events ApplicationLauncher.ApplicationActivated += OnApplicationActivated; ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed; ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated; //subscribing to the orientation changing event ApplicationLauncher.OrientationChanged += ApplicationLauncher_OrientationChanged; } void ApplicationLauncher_OrientationChanged(object sender, OrientationChangedEventArgs e) { // for simplicity, we consider that the application can be rotated only with 180 deg increments // so you'll not need to consider the scaling or moving the elements if the bottom becomes the shorter edge OrientationTransform.Angle = ApplicationLauncher.Orientation == UserOrientation.Top ? 180 : 0; // applying the orientation to UI elements OrientationTextBox.Text = ApplicationLauncher.Orientation.ToString(); }
That’s it folks – use and enjoy!