2014-10-09 16 views
0

我無法區分用戶是否明確切換切換開關,或者是否以編程方式打開/關閉切換開關。當彈出窗口啓動時,我需要爲切換開關設置初始值。然後,如果用戶明確更改值,則需要提出事件。 所以我試圖在ToggleSwitch上使用PointerReleased事件而不是Toggled事件,但是這在某些機器上不會被觸發。Windows 8.1 ToggleSwitch - 識別用戶是否明確切換

任何想法我可以如何解決這個問題?很多提前

感謝

回答

0

嘗試來包裝你ToggleSwitch在透明網格和集抽頭事件處理它。點擊事件只會通過用戶交互引發。您還需要在Tapped事件處理程序中以編程方式切換它以模擬標準行爲。

<Grid Tapped="ToggleSwitchGrid_Tapped" 
     Background="Transparent"> 
    <ToggleSwitch IsHitTestVisible="False" /> 
</Grid> 
0

PointerReleased事件可以解決您的問題。只要確定它是否像這樣留下指針即可:

void ToggleSwitch_PointerPressed(object sender, PointerRoutedEventArgs e) 
{ 
    // Check for input device 
    if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) 
    { 
     var properties = e.GetCurrentPoint(this).Properties; 
     if (properties.IsLeftButtonPressed) 
     { 
      // Left button pressed 
     } 
     else if (properties.IsRightButtonPressed) 
     { 
      // Right button pressed 
     } 
    } 
} 
相關問題