WP7 页面转换

发布于 2024-12-03 04:09:17 字数 3492 浏览 1 评论 0原文

我在 APP.XAML 中包含了一些代码来定义页面转换的一些样式。它包括在下面。

在我的 WP7 应用程序中,我有 3 个主要页面 - 例如 M1、M2 和 M3。对于它们中的每一个,我都在其 XAML 中标记为使用“TurnstileTransition”样式,当我在它们之间导航时,一切都运行良好。但是,我还有一个用于创建新项目的子页面 - 比如说我从 M2 和 M3 导航到的 S1。我的理解是,导航到这样的页面适合幻灯片过渡,对于这些页面,我使用“SlideTransition”样式。

当我导航到 S1 时,它似乎会选择从 M2(十字转门)向前导航,然后选择 S1(滑动)的向前导航。看起来有点乱。

我的问题是

  1. 我的假设是否正确并且它经历了这两个导航

  2. 是否有推荐的方法来处理这个问题 - 所以也许在哪里页面 (M2) 可以通过多种方式导航,然后它不会定义前向导航,而是将其保留在代码中完成。或者我是否需要转发导航并让它简单地从其要去的页面中获取导航中的转发?

  3. 假设我确实需要这样做,那么我会重写 XAML,我已将其标记为拾取样式,或者我现在需要在代码中完成这一切吗?

谢谢

<Style x:Key="TurnstileTransition" 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>
</Style>

<Style x:Key="SlideTransition" TargetType="phone:PhoneApplicationPage">
    <Setter Property="toolkit:TransitionService.NavigationInTransition">
        <Setter.Value>
            <toolkit:NavigationInTransition>
                <toolkit:NavigationInTransition.Backward>
                    <toolkit:SlideTransition Mode="SlideDownFadeIn"/>
                </toolkit:NavigationInTransition.Backward>
                <toolkit:NavigationInTransition.Forward>
                    <toolkit:SlideTransition Mode="SlideUpFadeIn"/>
                </toolkit:NavigationInTransition.Forward>
            </toolkit:NavigationInTransition>
        </Setter.Value>
    </Setter>
    <Setter Property="toolkit:TransitionService.NavigationOutTransition">
        <Setter.Value>
            <toolkit:NavigationOutTransition>
                <toolkit:NavigationOutTransition.Backward>
                    <toolkit:SlideTransition Mode="SlideUpFadeOut"/>
                </toolkit:NavigationOutTransition.Backward>
                <toolkit:NavigationOutTransition.Forward>
                    <toolkit:SlideTransition Mode="SlideDownFadeOut"/>
                </toolkit:NavigationOutTransition.Forward>
            </toolkit:NavigationOutTransition>
        </Setter.Value>
    </Setter>
</Style>

I have included some code within APP.XAML to define some styles for Page transitions. Its included below.

In my WP7 app I have 3 main pages - say M1, M2 and M3. For each of them I have marked in their XAML to use the 'TurnstileTransition' style and when I navigate between them it all works well. But, I also have a subpage that is used to create new items - say S1 that I navigate to from M2 and M3. My understanding is that navigating to a page like this suits a Slide transition and for these pages I am using the 'SlideTransition' style.

When I navigate to S1 it appears to pick up the Navigate forward out from M2 (turnstile) and then the Navigate ForwardIn for S1 (Slide). Looks a bit messy.

My questions are

  1. Is my assumption right and its going through both of these Navigations

  2. Is there a recommended approach to dealing with this - so maybe where a page (M2) can navigate away a couple of ways then its doesn't define the Forward Out Navigation but leaves this to be done in the code. Or do I need Forward out navigation and let it simply pick up the forward in navigation from the page to which its going to?

  3. Assuming I do need to do this then cam I override the XAML where I have marked it to pick up the style, or will I now need to do it all in the code??

Thanks

<Style x:Key="TurnstileTransition" 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>
</Style>

<Style x:Key="SlideTransition" TargetType="phone:PhoneApplicationPage">
    <Setter Property="toolkit:TransitionService.NavigationInTransition">
        <Setter.Value>
            <toolkit:NavigationInTransition>
                <toolkit:NavigationInTransition.Backward>
                    <toolkit:SlideTransition Mode="SlideDownFadeIn"/>
                </toolkit:NavigationInTransition.Backward>
                <toolkit:NavigationInTransition.Forward>
                    <toolkit:SlideTransition Mode="SlideUpFadeIn"/>
                </toolkit:NavigationInTransition.Forward>
            </toolkit:NavigationInTransition>
        </Setter.Value>
    </Setter>
    <Setter Property="toolkit:TransitionService.NavigationOutTransition">
        <Setter.Value>
            <toolkit:NavigationOutTransition>
                <toolkit:NavigationOutTransition.Backward>
                    <toolkit:SlideTransition Mode="SlideUpFadeOut"/>
                </toolkit:NavigationOutTransition.Backward>
                <toolkit:NavigationOutTransition.Forward>
                    <toolkit:SlideTransition Mode="SlideDownFadeOut"/>
                </toolkit:NavigationOutTransition.Forward>
            </toolkit:NavigationOutTransition>
        </Setter.Value>
    </Setter>
</Style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光是把杀猪刀 2024-12-10 04:09:17

如果您希望根据要导航到的页面进行更多页面转换,则应该重写 M2 页面的 OnNavigatingFrom 方法。在页面类中添加一个 bool 变量 ignoreTransition = false (这将告诉我们是否应该播放过渡),然后在 OnNavieratedFrom 方法中检查 IgnoreTransition 是否存在== false,如果ignoreTransition为false,则取消导航e.Cancel=true;并找到您正在导航到e.Uri的页面。如果 Uri 引用另一个 M 页面,则启动旋转栅门转换,否则启动滑动转换。

接下来,您需要订阅转换的 Completed 事件,并使用 lambda 表达式导航到您想要导航的页面:e.Uri。还要设置ignoreTransition = true;否则你将陷入循环。

最后但并非最不重要的一点:覆盖 OnNavigateFrom 并将 ignoreTransition 设置回 true

If you want to have more page transitions depending on which page you are navigating to you should override the OnNavigatingFrom method of let's say M2 page. Add a bool variable in your page class ignoreTransition = false (this will tell us if we should play the transition or not) then in the OnNavigatedFrom method check if IgnoreTransition == false, if ignoreTransition is false then cancel the navigation e.Cancel=true; and find which page you're navigating to e.Uri. If the Uri reffers to another M page start the turnstile transition, otherwise start the slide transition.

Next you need to subscribe to the transition's Completed event and using a lambda expression navigate to the page you wanted to navigate: e.Uri. Also set ignoreTransition = true; otherwise you will end up in a loop.

Last but not least: override OnNavigatedFrom and set ignoreTransition back to true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文