从一页滑动到另一页

Swipe from one page to another

如何让 Windows 通用应用程序的用户从一个页面滑动到另一个页面? (我以为这很容易找到,但搜索并没有找到答案。)

如果这在一页内是可能的 - 那也很好。 (将一个网格滑出并滑入另一个网格。)

枢轴控件的行为与您描述的一样。

参见guidelines for tabs and pivots

示例:

<Page x:Class="App1.MainPage"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Pivot>
        <PivotItem Header="Item 1" Background="Black" />
        <PivotItem Header="Item 2" Background="Red" />
        <PivotItem Header="Item 3" Background="Blue" />
    </Pivot>
</Grid>

我想说的是使用 FlipView 控件,但如果您的视图过于复杂,那可能会很危险。 FlipView 将保持您的页面呈现并随时准备翻转。我认为您可以尝试实现自己的东西以保持低内存使用率。也许使用 GestureRecognizer 这样您就可以控制用户可以滑动的位置并只呈现您需要的内容并丢弃任何过时的或屏幕外的内容。

Pivot 也会产生这种效果,但不同之处在于它必须将一个元素完全滑出屏幕,然后再将下一个元素滑入。它避免了同时呈现两个或三个视图,这对记忆有好处。但是,您将无法同时看到滑动 in/out 的两个页面。

两者都试一下,看看哪个最适合你。

您可以使用 GestureRecognizer 并操纵您想要做的事情。为 FX 创建动画。

我有一些与您的要求类似的东西:

如何"swipe"从一页到另一页:

在第 1 页(您将滑动 FROM 的页面) 制作一个网格,并将这些值放入:

XAML:

<Grid Padding="15,15,15,15" 
      HorizontalAlignment="Left" 
      VerticalAlignment="Stretch" 
      ManipulationMode="TranslateX,TranslateInertia,System" 
      ManipulationDelta="SwipeablePage_ManipulationDelta"
      ManipulationCompleted="SwipeablePage_ManipulationCompleted">

隐藏代码:

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

        if (Math.Abs(swipedDistance) <= 2) return;

        if (swipedDistance > 0)
        {
            // go to next page
            this.Frame.Navigate(typeof(Page2));
        }
        else
        {
            // do nothing 
        }
        _isSwiped = true;
    }
}