【问题标题】:Windows 8.1 ToggleSwitch - identify if user explicitly toggledWindows 8.1 ToggleSwitch - 识别用户是否显式切换
【发布时间】:2016-11-02 04:42:55
【问题描述】:

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

有什么办法可以解决这个问题吗?

非常感谢

【问题讨论】:

    标签: windows-8.1 toggleswitch


    【解决方案1】:

    尝试将您的 ToggleSwitch 包装在透明 Grid 中,并为其设置 Tapped 事件处理程序。 Tapped 事件将仅由用户交互引发。您还需要在 Tapped 事件处理程序中以编程方式切换它以模仿标准行为。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-29
        • 1970-01-01
        • 2017-10-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多