Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8.1 Windows 8.1 ToggleSwitch-确定用户是否显式切换_Windows 8.1_Toggleswitch - Fatal编程技术网

Windows 8.1 Windows 8.1 ToggleSwitch-确定用户是否显式切换

Windows 8.1 Windows 8.1 ToggleSwitch-确定用户是否显式切换,windows-8.1,toggleswitch,Windows 8.1,Toggleswitch,我无法区分用户是显式切换切换开关还是以编程方式打开/关闭切换开关。当弹出窗口启动时,我需要为toggleswitch设置初始值。然后,若用户显式更改值,我需要引发一个事件。 因此,我尝试在ToggleSwitch上使用PointerReleased事件而不是Toggled事件,但在某些机器上不会触发该事件 有没有办法解决这个问题 提前多谢尝试将您的切换开关包装在透明的网格中,并将点击事件处理程序设置为它。点击事件将仅由用户交互引发。您还需要在点击事件处理程序中以编程方式切换它,以便模拟标准行为

我无法区分用户是显式切换切换开关还是以编程方式打开/关闭切换开关。当弹出窗口启动时,我需要为toggleswitch设置初始值。然后,若用户显式更改值,我需要引发一个事件。 因此,我尝试在ToggleSwitch上使用PointerReleased事件而不是Toggled事件,但在某些机器上不会触发该事件

有没有办法解决这个问题


提前多谢

尝试将您的切换开关包装在透明的网格中,并将点击事件处理程序设置为它。点击事件将仅由用户交互引发。您还需要在点击事件处理程序中以编程方式切换它,以便模拟标准行为

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

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
        }
    }
}