• Windows phone中如何添加页面跳转动画


    有没有羡慕ios平台中华丽的动画效果,不用担心微软的toolkit团队为我们为我们提供了这样一套组件,叫做TransitionServices服务。

    简单说一下它具备的效果:turnstile(轴旋转效果);turnstile feather(羽毛式轴旋转效果);continuum(继承动画效果);slide(滑动效果);rotate(旋转效果)。这里我们实现一下Turnstile效果:

    接下来我介绍一下使用过程(这里实现一个全局的跳转动画,某个页面需要动画效果时直接添加style属性就可以了):

          首先毋庸置疑我们要下载Silverlight for Windows Phone Toolkit (没有Windows phone Toolkit的可以去http://silverlight.codeplex.com/releases/view/55034/ 进行下载):

          因为想实现全局都可以调用的动画,于是我们可以在App.xaml中实现我们的想法。

            1.首先将Toolkit引用进来:在Application中加入  xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 即可:如图

              

           2.在 <Application.Resources>中添加一个动画样式(Style标签中的便是):

      <!--应用程序资源-->
        <Application.Resources>
            <local:LocalizedStrings xmlns:local="clr-namespace:MeeTu" x:Key="LocalizedStrings"/>
            <UriMapper:UriMapper x:Name="mapper">
                <UriMapper:UriMapping Uri="/MainPage.xaml" />
            </UriMapper:UriMapper>
            <Style x:Key="PageTranstionStyle" TargetType="phone:PhoneApplicationPage">
                <Setter Property="toolkit:TransitionService.NavigationInTransition">
                    <Setter.Value>
                        <toolkit:NavigationInTransition>
                            <toolkit:NavigationInTransition.Backward>
                                <toolkit:TurnstileTransition Mode="BackwardIn"/>
                            </toolkit:NavigationInTransition.Backward>
                            <toolkit:NavigationInTransition.Forward>
                                <toolkit:TurnstileTransition Mode="ForwardIn" />
                            </toolkit:NavigationInTransition.Forward>
                        </toolkit:NavigationInTransition>
                    </Setter.Value>
                </Setter>
                <Setter Property="toolkit:TransitionService.NavigationOutTransition">
                    <Setter.Value>
                        <toolkit:NavigationOutTransition>
                            <toolkit:NavigationOutTransition.Backward>
                                <toolkit:TurnstileTransition Mode="BackwardOut"/>
                            </toolkit:NavigationOutTransition.Backward>
                            <toolkit:NavigationOutTransition.Forward>
                                <toolkit:TurnstileTransition Mode="ForwardOut" />
                            </toolkit:NavigationOutTransition.Forward>
                        </toolkit:NavigationOutTransition>
                    </Setter.Value>
                </Setter>
                <Setter Property="Background">
                    <Setter.Value>
                        <ImageBrush ImageSource="/Images/bg2.png"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </Application.Resources>

           3.这一点很重要,我们需要在App.xaml.cs文件中修改下东西,以便于我们的动画能被调用。

              在cs文件中找到"RootFrame = new PhoneApplicationFrame();" 也就是PhoneApplicationFrame的实例化方法,

              我们将它改成:"RootFrame = new TransitionFrame();"  这样我们的框架就成为了一个可以有跳转动画的框架了。

           4.接下来就是调用了,这个很简单直接在想用动画的页面里加上这个style就可以了: Style="{StaticResource PageTranstionStyle}":如图:

    <phone:PhoneApplicationPage
        x:Class="MeeTu.Message.SendMessagePage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d"
        Style="{StaticResource PageTranstionStyle}"
        shell:SystemTray.IsVisible="False">
    
        <!--LayoutRoot 是包含所有页面内容的根网格-->
        <Grid x:Name="LayoutRoot">
            <Grid.Background>
                <ImageBrush ImageSource="/Images/bg2.png"/>
            </Grid.Background>
        </Grid>
        <phone:PhoneApplicationPage.ApplicationBar>
            <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Mode="Default" BackgroundColor="Black" ForegroundColor="White">
                <shell:ApplicationBarIconButton Text="send" IconUri="/Icons/check.png" Click="ApplicationBarIconButton_Click_Send" />
                <shell:ApplicationBar.MenuItems>
                    <shell:ApplicationBarMenuItem Text="Settings" />
                    <shell:ApplicationBarMenuItem Text="Profile" />
                    <shell:ApplicationBarMenuItem Text="Sign out" />
                </shell:ApplicationBar.MenuItems>
            </shell:ApplicationBar>
        </phone:PhoneApplicationPage.ApplicationBar>
    
    </phone:PhoneApplicationPage>

         最后:除了自带的这些动画效果外,我们同样可以自定义动画,这个我以后再同大家分享。

            

  • 相关阅读:
    [收藏转贴]struct探索·extern "C"含义探索 ·C++与C的混合编程·C 语言高效编程的几招
    [收藏转贴]构建RESTful风格的WCF服务
    [转贴] C/C++中动态链接库的创建和调用
    [转贴]WebService的简单实现 C++
    谷歌已经对Android的开源严防死守
    如何成为一名黑客?
    当程序员思路被打断
    编辑语言是这样的
    开发者需要掌握多少门语言?
    程序员的六大优势
  • 原文地址:https://www.cnblogs.com/zhangfan19900327/p/3110375.html
Copyright © 2020-2023  润新知