简体   繁体   English

从一页滑到另一页

[英]Swipe from one page to another

How can I let a user of a Windows Universal App swipe from one page to another? 如何让Windows Universal App的用户从一页滑动到另一页? (I thought this would be easy to find, but searching hasn't uncovered the answer.) (我认为这很容易找到,但是搜索并没有找到答案。)

And if this is possible within one page - that's fine too. 如果可以在一页内完成-也可以。 (To swipe one grid out and another in.) (向内滑动一个网格,向内滑动另一个网格。)

Pivot control behaves like you discribed. 枢轴控件的行为就像您描述的那样。

See guidelines for tabs and pivots . 有关标签和枢轴的信息,请参见准则

Example: 例:

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

You can use GestureRecognizer and manipulate what you wanna do. 您可以使用GestureRecognizer并操纵您想做的事情。 Create animation for the FX. 为FX创建动画。

I want to say use a FlipView control, but that could be dangerous if your views are too complex. 我想说的是使用FlipView控件,但是如果您的视图过于复杂,那可能会很危险。 FlipView will keep your pages rendered and ready to be flipped to at all times. FlipView将使您的页面保持渲染状态,并随时可以翻转。 I think you can try to implement your own thing to keep memory usage low. 我认为您可以尝试实现自己的东西以保持较低的内存使用率。 Maybe use a GestureRecognizer so that you have control over where the user can swipe and only render what you need and discard anything obsolete or off the screen. 也许使用GestureRecognizer,这样您就可以控制用户可以在何处滑动,仅呈现所需的内容,并丢弃任何过时或不在屏幕上的内容。

Pivot will also create this effect, but the difference is that it must completely slide one element off the screen and then slide the next one in. It keeps from having two or three views rendered at once, which is good for memory. Pivot也会产生这种效果,但是不同之处在于,它必须将一个元素完全滑出屏幕,然后再将下一个元素滑入屏幕。它不会一次渲染两个或三个视图,这对内存很有用。 However, you won't be able to see both pages sliding in/out at the same time. 但是,您将无法同时看到两个页面的滑动。

Try them both, see which is best for you. 都尝试一下,看看哪种最适合您。

I have something similiar to what you're asking: 我有一些与您要问的类似的东西:

How to "swipe" from one page to another: 如何“滑动”从一页到另一页:

On page 1 (The page where you will swipe FROM) Make a grid, and put these values in: 在第1页上(从中滑动FROM的页面)制作一个网格,并将这些值放在:

XAML: XAML:

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

Code Behind: 背后的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM