Carousel UWP Microsoft Toolkit 禁用滑动

Carousel UWP Microsoft Toolkit disable swipe

我使用来自 Microsoft.UWP.Toolkir.Controls 的 Carousel 控件 https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/carousel

当我们点击并按住鼠标左键时,我们可以像在平板电脑中一样滑动项目,phohe。就像 "panoramic" 滚动一样。

所以,它正常工作,但是当我们在第一个和最后一个项目上按住并移动指针(或手指)时,我们得到左边的白色 "background"(mb 偏移量)(第一个项目) ), 右(最后一项)边。

当我们移动并且项目得到一些(我不知道如何检查)水平偏移时 -> 它回到以前的状态。

start position carousel view

we hold and move first item, left of it we get some offset

我们能否在第一项和最后一项上获取并更改此偏移量或禁用此选项?

Can we get and change this offset or disable this option on first and last item?

Windows Community Toolkit is open source, you could check the Carousel源代码。

你说的'当我们在第一个和最后一个项目上按住并移动指针(或手指)时,我们得到白色"background" (mb offset) left (first item), right (last item) sides.' 才正常Manipulation operation. You could see these operations in CarouselPanel.cs.

为了达到你的目的,你需要在OnManipulationDelta中进行判断,如果选择的item是第一个或最后一个item,你可以像下面这样终止Manipulation:

internal void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    var previousIndex = Carousel.SelectedIndex;
    var delta = Carousel.Orientation == Orientation.Horizontal ? e.Delta.Translation.X : e.Delta.Translation.Y;
    if ((previousIndex == 0 && delta>0)||(previousIndex==Children.Count-1 && delta<0))
    {
        return;
    }
    ........
}

以上代码只是我的简单实现,如果觉得不合适可以自行修改。

然后,当您在 Windows Community Toolkit 中更改源代码时,您必须为其编译自定义版本并在您的项目中添加对它的引用。