Windows Phone 8.1 Page transitions

original: http://www.visuallylocated.com/post/2014/06/24/Page-transitions-and-animations-in-Windows-Phone-Runtime.aspx

With the release of Windows Phone 8.1 Runtime (aka XAML) comes a lot of functionality that previously only existed in the Windows Phone Toolkit or other third party control suites. One of these are page transitions and animations on objects. In Windows Phone 8 apps your best option for page transitions was the Windows Phone Toolkit or Telerik. I’ve used both, but really enjoy the robustness and ease of use of Teleriks transitions. With Teleriks RadTransitionControl you could setup forward and backward animations with three lines of XAML! Contrast that with the Windows Phone Toolkit where it takes 20 lines of XAML!! Because I like Teleriks transitions this post will cover moving from the Windows Phone Toolkit or the Teleriks transitions to the new transitions in the Windows Phone Runtime.

In both the Windows Phone Toolkit and Telerik you had to set the RootFrame of the App to be the control suite transition frame.

// Default
RootFrame = new PhoneApplicationFrame();
 
// WP Toolkit
RootFrame = new TransitionFrame();
 
// Telerik
RootFrame = new RadPhoneApplicationFrame();

With Windows Phone Runtime apps you do not need to do anything. When you create a new phone project, everything will be setup so that every page will show a turnstile transition! The transitions are setup within the RootFrame_FirstNavigated method,

rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };

Note: It is important to set the ContentTransitions of the frame. If this is null your app can crash while trying to navigate.

This sets up your app to show the NavigationThemeTransition. This is a “generic” transition that can be used all by itself. With this one line of code, every page you navigate to will use a turnstile transition!

The NavigationThemeTransition has a property, DefaultNavigationTransitionInfo, that specifies what transition to use for the page. There are three default classes that can be used, CommonNavigationTransitionInfo, SlideNavigationTransitionInfo. and ContinuumNavigationTransitionInfo. Setting up a page to use one of these is pretty simple.

<Page.Transitions>
    <TransitionCollection>
        <NavigationThemeTransition>
            <NavigationThemeTransition.DefaultNavigationTransitionInfo>
                <SlideNavigationTransitionInfo/>
            </NavigationThemeTransition.DefaultNavigationTransitionInfo>
        </NavigationThemeTransition>
    </TransitionCollection>
</Page.Transitions>

I’m not going to show how the WPToolkit or Telerik equivalent for the transitions as it would be too much.

The CommonNavigationTransitionInfo is the default NavigationTransitionInfo. It states that the page will use the turnstile transition. The CommonNavigationTransitionInfo also allows you to specify that a feather (aka stagger) page transitionshould be used. SlideNavigationTransitionInfo states that the page will use a slide transition that will animate from bottom to top when navigating in and top to bottom when navigating out. Finally, the ContinuumNavigationTransitionInfo allows you to show a “Fly away” transition like when tapping an email in the mail app. I’ll go into this in another post as well.

Along with the NavigationThemeTransition, there are other transitions that can be used for pages. The PaneThemeTransition and EdgeUIThemeTransition provide exactly the same functionality. They both allow you to use a slide transition, but to specify which edge to slide the content in from, and out to.

<TransitionCollection>
    <PaneThemeTransition Edge="Bottom" />
</TransitionCollection>

The EntranceThemeTransition is pretty cool because it allows you specify the horizontal and vertical offset that the page should navigate from. This means you can slide your page in diagonally.

<TransitionCollection>
    <EntranceThemeTransition FromVerticalOffset="200" FromHorizontalOffset="200" />
</TransitionCollection>

Those are the basic page transitions for pages. One really awesome thing that you can do with the new transitions is create what I call partial and complex transitions. This technique requires that you do not set a default transition to the root frames ContentTransitions like is done by default. You still need to create a new TransitionCollection, but do not put anything in it! With a partial or complex transition, you will [most likely] not set a transition for the page. Instead you will place transitions on the ChildrenTransitions of individual panels. The example below uses the EdgeUIThemeTransition is a sample of what I call a “complex transition”. It  slides items in from alternating sides.

<StackPanel Margin="0,0,0,9.5">
    <StackPanel.ChildrenTransitions>
        <TransitionCollection>
            <EdgeUIThemeTransition Edge="Right"/>
        </TransitionCollection>
    </StackPanel.ChildrenTransitions>
    <TextBlock Text="Item One" Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>
<StackPanel Margin="0,0,0,9.5">
    <StackPanel.ChildrenTransitions>
        <TransitionCollection>
            <EdgeUIThemeTransition Edge="Left"/>
        </TransitionCollection>
    </StackPanel.ChildrenTransitions>
    <TextBlock Text="Item Two" Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>
<StackPanel Margin="0,0,0,9.5">
    <StackPanel.ChildrenTransitions>
        <TransitionCollection>
            <EdgeUIThemeTransition Edge="Right"/>
        </TransitionCollection>
    </StackPanel.ChildrenTransitions>
    <TextBlock Text="Item Three" Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>

Aside from page transitions, there are some awesome animations that can be used on items. One exciting animation is tilt. Tilt is enabled on all “clickable” items by default (eg: Button, ListViewItem)! This is exciting because previously you had to set this yourself. There are a few ways to enable tilt on non-clickable items, read this post to find out more. Another awesome animation is the slide in animation that you get when changing PivotItems within a Pivot. This is a staggered slide that you get for each line of an item. Enabling this requires setting the SlideInAnimationGroup on each element you want to stagger sliding.

<DataTemplate>
    <StackPanel Margin="0,0,0,9.5">
        <TextBlock Pivot.SlideInAnimationGroup="1"
                   Text="{Binding Title}"
                   Style="{ThemeResource ListViewItemTextBlockStyle}"
                   Margin="0,0,19,0"/>
        <TextBlock Pivot.SlideInAnimationGroup="2" 
                   Text="{Binding Description}"
                   TextWrapping="WrapWholeWords"
                   Style="{ThemeResource ListViewItemContentTextBlockStyle}"
                   Margin="0,0,19,0"/>
    </StackPanel>
</DataTemplate>

I have noticed a weird bug with this animation in which items do not slide in when first changing pivot items. Keep this in mind when testing.

Another handy animation is the AddDeleteThemeTransition. With this transition, when an item is added it will open a space and be inserted into that space. When an item is removed, the item will go away and then the content will slide up in its place. This transition is already enabled on the ListView and GridView.

<ItemsControl ItemsSource="{Binding Items}" 
              ItemTemplate="{StaticResource ItemsTemplate}">
    <ItemsControl.ItemContainerTransitions>
        <TransitionCollection>
            <AddDeleteThemeTransition/>
        </TransitionCollection>
    </ItemsControl.ItemContainerTransitions>
</ItemsControl>

时间: 2024-11-09 00:31:09

Windows Phone 8.1 Page transitions的相关文章

背水一战 Windows 10 (42) - 控件(导航类): Frame 动画

原文:背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 [源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) Frame 动画 示例Animation/NavigationTransitionInfo/Demo.xaml <Page x:Class="Windows10.Animation.NavigationTransitionInfo.Demo" xmlns="http://schemas.mic

What is the purpose for IT Pro in Windows 10 Creators Update

Windows 10, version 1703-also known as the Windows 10 Creators Update-is designed for today's modern IT environment with new features to help IT pros more easily manage, and better protect, the devices and data in their organizations. It also provide

wp8.1 Study8:页面过渡和主题动画(Page transition and Theme animations)

一.在WP8.1中是有动画(Animation)的: 页面导航(默认为旋转式Turnstile).PointerDown/up(默认是倾斜).页面旋转.MenuFlyout出现等等 二.页面过渡(Page transition) 1.默认的动画是旋转式(Turnstile). 2.除了默认的动画,我们还可以运用ContinuumNavigationTransitionInfo.Stagger.Slide等类似过渡. 三.重写默认过渡/动画 (1)在控件中,我们可以这样做,XAML代码如下: <!

[WP8.1UI控件编程]Windows Phone XAML页面的编译

1.1.2 XAML页面的编译 Windows Phone的应用程序项目会通过Visual Studio完成XAML页面的编译,在程序运行时会通过直接链接操作加载和解析XAML,将XAML和过程式代码自动连接起来.如果你不在乎将XAML文件和过程式代码融合,那么只需要把它添加到Visual Studio的Windows Phone项目中来,并用界面中的Build动作来完成编译即可,一般公共的样式资源的XAML文件都是采用这种方式.但是如果要编译一个XAML文件并将它与过程式代码混合,第一步要做的

Windows API参考大全新编

书名:新编Windows API参考大全 作者:本书编写组 页数:981页 开数:16开 字数:2392千字 出版日期:2000年4月第二次印刷 出版社:电子工业出版社 书号:ISBN 7-5053-5777-8 定价:98.00元 内容简介 作为Microsoft 32位平台的应用程序编程接口,Win32 API是从事Windows应用程序开发所必备的.本书首先对Win32 API函数做完整的概述:然后收录五大类函数:窗口管理.图形设备接口.系统服务.国际特性以及网络服务:在附录部分,讲解如何

WPF窗口跳转及window和page区别

分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net 刚接触WPF,有两个概念不是很懂,现理解如下: 1:window和page谁包含谁的问题 一新建WPF应用程序,发现默认启动界面是一个window,将默认启动改为page,没有错误.但是如果在page中执行如下程序报错: this.content = new Window1(); 错误信息是:window是在属性结构的根目录.那么,

web development blog(转)

Top 10 jQuery Mobile Code Snippets that you need to know jQuery Mobile is a framework for mobile web apps and mobile websites with an aim to provide a unified user interface system across many mobile device platforms such iPhone, BlackBerry, Android

access violation at address General protection fault

https://en.wikipedia.org/wiki/General_protection_fault In memory errors, the faulting program accesses memory that it should not access. Examples include: Attempting to write to a read-only portion of memory Attempting to execute bytes in memory whic

[转载]SQL Server内核架构剖析

原文链接:http://www.sqlserver.com.cn 我们做管理软件的,主要核心就在数据存储管理上.所以数据库设计是我们的重中之重.为了让我们的管理软件能够稳定.可扩展.性能优秀.可跟踪排错.可升级部署.可插件运行, 我们往往研发自己的管理软件开发平台.我们总是希望去学习别人的开发平台(如用友或金蝶或SAP),但我们却总是感叹管理软件业务处理细节繁多, 而数据库管理软件却简单的SELECT.INSERT.DELETE.UPDATE四个命令就搞定. 我们多希望有一天能做出一个架构,也可