在 WP7 silverlight 应用程序和转换中加载数据

发布于 2024-11-04 00:53:33 字数 2629 浏览 1 评论 0原文

我正在制作一个 WP7 Silverlight 应用程序,并使用 ViewModel 来存储数据并作为页面的数据上下文。

每个 PhonePage 都有自己的数据,我在 Page_Loaded 事件处理程序中调用 App.ViewModel.LoadData()。有一个 ListBox 显示 ViewModel 中的数据。

我使用 Codeplex 的 Silverlight 工具包中的 TurnstileTransition 转换。 (http://silverlight.codeplex.com/releases/view/60291)

进一步澄清 转换在 App.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="{StaticResource TurnstileTransition}"

一切正常。

但是,在转换完成之前,数据已绑定到列表框!

这看起来很难看!

我可以在转换的END处处理该事件吗(所以我加载此处的数据并绑定它),如果可以的话我在哪里添加事件处理程序?

我可以在转换的开始处处理事件吗(所以我清除此处的数据),如果可以,我在哪里添加事件处理程序?

您是否建议我必须考虑其他解决方案?

我如何将事件处理程序添加到转换的完成事件中,转换对象的名称是什么? 转换有 2 种类型的转换,我可以检测到哪种类型的转换(向前或向后)发生并完成吗?

I am making a WP7 Silverlight application and using a ViewModel to store the data and as the datacontext for the pages.

Each PhonePage has its own data and I call the App.ViewModel.LoadData() in the Page_Loaded event-handler. There is a ListBox which shows the Data in the ViewModel.

I use the TurnstileTransition transition from the Silverlight toolkit from Codeplex. (http://silverlight.codeplex.com/releases/view/60291)

FURTHER CLARIFICATION
The transition is defined as a resource in App.xaml as:

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

And every page has the style defined as:

Style="{StaticResource TurnstileTransition}"

Everything works fine.

However, the data is bound to the Listbox BEFORE the Transition has finished!!

This looks ugly!

Can I handle the event at the END of the transition (So I load the data here and bind it), if so where do i add the eventhandler??

Can I handle the event at the START of the transition (So I clear the data here), if so where do i add the eventhandler??

Do you suggest some other solution that I must consider?

How can i add an event-handler to the Transition's completed event, what is the name of the transition object??
And transition has 2 types of transitions, can i detect in which type (Forward or Backward) of transition happened and completed?

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

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

发布评论

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

评论(2

倒带 2024-11-11 00:53:33

尝试这个(在您要导航到的页面的上下文中)

        var transition = TransitionService.GetNavigationInTransition(this); //This being the page with the associated navigation
        transition.EndTransition += transition_EndTransition;

...
        void transition_EndTransition(object sender, System.Windows.RoutedEventArgs e)
        {
            DataContext = ...;
        }

我这样做是为了获得更平滑的动画,因为否则我需要做的数据库工作会破坏过渡的流畅性,因为如果我在 OnNavigedTo 中运行它,它执行得太早'事件'

Try this (within the context of the page you're navigating to)

        var transition = TransitionService.GetNavigationInTransition(this); //This being the page with the associated navigation
        transition.EndTransition += transition_EndTransition;

...
        void transition_EndTransition(object sender, System.Windows.RoutedEventArgs e)
        {
            DataContext = ...;
        }

I did this to get a smoother animation because otherwise the DB work I needed to do ruined the fluidity of the transition because it executed too early if I ran it in the OnNavigatedTo 'event'

潦草背影 2024-11-11 00:53:33

转换有一个 Completed 事件,您可以使用该事件来标识转换的结束。

没有启动事件,但您可以在导航到具有转换的页面之前触发与此等效的事件。

A Transition has a Completed event which you could use to identify the end of the transition.

There isn't a started event but you could trigger something equivalent to this before you navigate to the page with the transition.

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