如何让Windows Universal App的用户从一个页面滑动到另一个页面? (我觉得这很容易找到,但搜索没有发现答案。)
如果这可以在一页内完成 - 那也没关系。 (要滑出一个网格,另一个网格。)
枢轴控制的行为与您描述的相似。
见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>
你可以使用GestureRecognizer并操纵你想做的事情。为FX创建动画。
我想说使用FlipView
控件,但如果你的观点过于复杂,这可能会很危险。 FlipView
将保持您的页面呈现,并随时可以翻转。我认为你可以尝试实现自己的东西来保持低内存使用率。也许使用GestureRecognizer,以便您可以控制用户可以滑动的位置,只能渲染您需要的内容,并丢弃任何过时或屏幕外的内容。
Pivot
也会产生这种效果,但不同之处在于它必须将一个元素从屏幕上完全滑出然后滑入下一个元素。它不会同时渲染两个或三个视图,这对内存有好处。但是,您将无法同时看到两个页面滑入/滑出。
尝试两者,看看哪个最适合你。
我有类似于你问的东西:
如何从一个页面“滑动”到另一个页面:
在第1页(您将从中滑动的页面)创建一个网格,并将这些值放入:
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;
}
}