# How to detect a Left snap or a right snap?

• ### Question

• I wish to detect whether my app has been snapped/filled to the left or right of the screen - but whilst I can detect when something has snapped/filled there doesn't seem to be any obvious way to detect what side of the screen something has been snapped/filled to.

Can anyone suggest a solution?

Wednesday, November 7, 2012 11:12 PM

• The application has no way to know if it has been snapped to the right or left. Your application should just be able to handle if it is snapped or not snapped.

Thanks,

Prashant.

Thursday, November 8, 2012 1:39 AM

### All replies

• The application has no way to know if it has been snapped to the right or left. Your application should just be able to handle if it is snapped or not snapped.

Thanks,

Prashant.

Thursday, November 8, 2012 1:39 AM
• Actually that's pretty poor because I am building a touch screen system that draws an imaginary line down the centre of the play area.  That line needs to be specified in screen co-ordinates (because touch points are given in screen co-ordinates) therefore the imaginary line's position would differ based on a left or right snap.

Neverthless I have found an easy way to detect it myself.  When snapped to the left the window.screenX property = 0 and when snapped to the right window.screenX > 0

I still think it would be useful to provide a more intuitive way of knowing whether a left or right snap has occured because I could see other scenarios where you may wish to know

Thursday, November 8, 2012 3:58 PM
• Have you actually debugged your application and got any random values for window.screenX property for snapped left and right??

What I am trying to understand is if you need to draw a line in the middle, which can be relative to your screen, and why specific points are needed??

Arindam Basu

Friday, November 9, 2012 5:03 AM
• "When snapped to the left the window.screenX property = 0 and when snapped to the right window.screenX > 0"
This is the correct way to do it.
• Proposed as answer by Sunday, November 11, 2012 6:34 PM
Sunday, November 11, 2012 6:34 PM
• It is great but if you move application from one snapped side directly to another snapped side size of the window won't be changed.

And how in that case determine that you moved it to another side?

Friday, December 21, 2012 9:58 AM
• You'd have to create a loop that checks the value of window.screenX 30 times a second or so like this:

```var currentSide;

function onViewStateChanged(eventArgs) {
var viewStates Windows.UI.ViewManagement.ApplicationViewState, msg;
var newViewState = Windows.UI.ViewManagement.ApplicationView.value;
if (newViewState === viewStates.snapped) {
currentSide = window.screenX;
var sideChecker = setInterval(function () {
if (window.screenX > currentSide){
//change from left to right side
currentSide = window.screenX;
}
else if (window.screenX < currentSide){
//change from right to left side
currentSide = window.screenX;
}
}, 1000/30); // 30 checks per second
}
else
clearInterval(sideChecker);
}```

I haven't tested this, but you get the idea. Once the snapped it triggers the event and the loop will start. The loop will be killed if you go back to a non-snapped state. If the side changes it will trigger its respective code block once.

• Edited by Friday, December 21, 2012 8:32 PM
Friday, December 21, 2012 8:24 PM