2012-12-27 57 views
2

如何使用JavaScript檢查snapview是否正常工作。SnapView檢查javascript

var SNAPPED_VIEW = 320; 

window.addEventListener("resize", onViewStateChanged); 

function onViewStateChanged(eventArgs) { 
    var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg; 
    var newViewState = Windows.UI.ViewManagement.ApplicationView.value; 
    if (newViewState === viewStates.snapped) { 
     var msg = new Windows.UI.Popups.MessageDialog("snap view mode"); 
    } else if (newViewState === viewStates.filled) { 
     showMenu('filled'); 
    } else if (newViewState === viewStates.fullScreenLandscape) { 
     showMenu('landscape'); 
    } else if (newViewState === viewStates.fullScreenPortrait) { 
     //Currently not supported 
    } 
} 

使用此代碼我試圖做的,但它是用破發點時,顯示不確定的。

+1

具體什麼是不確定的?你的對話框不會真的做任何事情,因爲你沒有顯示它,但你的代碼似乎只是通過將它放到default.js中正確工作。 –

回答

0

正如吉姆說,你的代碼工作完全正常,但你沒有顯示你的對話討論。我只是添加了不同意見的文本框,並賦值和它的作品完美的罰款:

var SNAPPED_VIEW = 320; 

window.addEventListener("resize", onViewStateChanged); 

function onViewStateChanged(eventArgs) { 
    var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg; 
    var newViewState = Windows.UI.ViewManagement.ApplicationView.value; 
    if (newViewState === viewStates.snapped) { 
    document.getElementById("screenMode").innerText = "s"; 
    } else if (newViewState === viewStates.filled) { 
    document.getElementById("screenMode").innerText = "f"; 
    } else if (newViewState === viewStates.fullScreenLandscape) { 
    document.getElementById("screenMode").innerText = "l" 
    } else if (newViewState === viewStates.fullScreenPortrait) { 
    //Currently not supported 
    } 
} 

HTML:

<input type="text" id="screenMode"/>