【问题标题】:ManipulationDelta on pivot item only fires once枢轴项目上的 ManipulationDelta 仅触发一次
【发布时间】:2014-06-12 16:05:14
【问题描述】:

我正在尝试根据选择的旋转项目位置为图像设置动画。

我目前正在使用 ManipulationDelta 事件来尝试查看用户滑动的方向,以便我可以根据枢轴项目的位置淡出或淡入动画图像。

我的问题在于 ManipulationDelta 事件,无论发生多少枢轴控件操作,此事件仅在枢轴项目上调用一次。

有没有人知道一种方法来使枢轴项目 ManpulationDelta 事件在被操纵时不断被调用?

【问题讨论】:

    标签: xaml events windows-phone-8 gesture


    【解决方案1】:

    您的Pivot 可能正在拦截更多事件。你可以尝试做这样的事情——禁用Pivot(然后你的操作应该起作用)并手动更改PivotItems,例如使用TouchPanelTouch.FrameReported。示例代码:

    public MainPage()
    {
       InitializeComponent();
       myPivot.IsHitTestVisible = false; // disable your Pivot
       Touch.FrameReported += Touch_FrameReported;
       TouchPanel.EnabledGestures = GestureType.HorizontalDrag; 
    }
    
    TouchPoint first;
    private const int detectRightGesture = 20;
    
    private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        TouchPoint mainTouch = e.GetPrimaryTouchPoint(this);
        if (mainTouch.Action == TouchAction.Down)
            first = mainTouch;
        else if (mainTouch.Action == TouchAction.Up && TouchPanel.IsGestureAvailable)
        {
            if (mainTouch.Position.X - first.Position.X < -detectRightGesture)
            {
                if (myPivot.SelectedIndex < myPivot.Items.Count - 1) myPivot.SelectedIndex++;
                else myPivot.SelectedIndex = 0;
            }
            else if (mainTouch.Position.X - first.Position.X > detectRightGesture)           
            {
                if (myPivot.SelectedIndex > 0) myPivot.SelectedIndex--;
                else myPivot.SelectedIndex = myPivot.Items.Count - 1;
            }
        }
    }
    

    【讨论】:

    • 这在一定程度上有效,但您失去了对枢轴控件的手动操作。无论如何,干杯这对我来说确实有帮助。
    • @TomWiddowson 是的,如果您不希望 Pivot 拦截事件,则必须禁用它。我很高兴它以某种方式有所帮助;)
    猜你喜欢
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    相关资源
    最近更新 更多