首页 > 解决方案 > 使用自定义渲染器 UWP 打开 SwipeView

问题描述

几天以来,我一直在尝试寻找一种方法来引发滑动,使用鼠标打开 Xamarin Forms SwipeView。我在这里找到了图片中的解决方案,至少我有事件发生并且解释是正确的。问题是我有控制台消息,但它不会打开。我做了界面,Asbstract 基类,没有任何东西可以让我打开滑动。有人有想法吗?[程序集:ExportRenderer(typeof(SwipeView), typeof(SwipeViewRendererUWP))]

    public class SwipeViewRendererUWP : SwipeViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<SwipeView> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateInertia;
            Control.ManipulationDelta += Control_ManipulationDelta;
            Control.ManipulationCompleted += Control_ManipulationCompleted;
            Control.ManipulationStarted += Control_ManipulationStarted;
            Control.PointerPressed += Control_PointerPressed;
            Control.PointerReleased += Control_PointerReleased;
        }
    }

    private void Control_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
    {
    }

    private void Control_PointerReleased(object sender, PointerRoutedEventArgs e)
    {
        ReleasePointerCaptures();
    }

    private void Control_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        CapturePointer(e.Pointer);
    }

    private bool _isSwiped;

    private void Control_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        Server.ConsoleDebug("Swipe Ended");
        _isSwiped = false;
    }

    private void Control_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        if (e.IsInertial && !_isSwiped)
        {
            var swipedDistance = e.Cumulative.Translation.X;

            if (Math.Abs(swipedDistance) <= 2) return;
            {
                if (swipedDistance > 0)
                {
                    
                    Element.Open(OpenSwipeItem.LeftItems);
                    Server.ConsoleDebug("left swipe");
                }
                else
                {
                    Element.Open(OpenSwipeItem.RightItems);
                    Server.ConsoleDebug("right swipe");
                }

                _isSwiped = true;
            }

        }
    }
}

标签: c#xamarin.formsshared-librariesxamarin.uwpswipeview

解决方案


推荐阅读