简体   繁体   English

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

[英]Loading data in WP7 silverlight application and transitions

I am making a WP7 Silverlight application and using a ViewModel to store the data and as the datacontext for the pages.我正在制作一个 WP7 Silverlight 应用程序并使用 ViewModel 来存储数据并作为页面的数据上下文。

Each PhonePage has its own data and I call the App.ViewModel.LoadData() in the Page_Loaded event-handler.每个 PhonePage 都有自己的数据,我在 Page_Loaded 事件处理程序中调用App.ViewModel.LoadData() There is a ListBox which shows the Data in the ViewModel.有一个 ListBox 显示 ViewModel 中的数据。

I use the TurnstileTransition transition from the Silverlight toolkit from Codeplex.我使用来自 Codeplex 的 Silverlight 工具包的TurnstileTransition转换。 (http://silverlight.codeplex.com/releases/view/60291) (http://silverlight.codeplex.com/releases/view/60291)

FURTHER CLARIFICATION The transition is defined as a resource in App.xaml as:进一步澄清过渡在 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>

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??如何向转换的已完成事件添加事件处理程序,转换 object 的名称是什么? And transition has 2 types of transitions, can i detect in which type (Forward or Backward) of transition happened and completed?并且过渡有两种类型的过渡,我可以检测到哪种类型的过渡(向前或向后)发生并完成了吗?

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'我这样做是为了获得更平滑的 animation 因为否则我需要做的数据库工作破坏了过渡的流动性,因为如果我在 OnNavigatedTo '事件'中运行它,它执行得太早了

A Transition has a Completed event which you could use to identify the end of the transition.转换有一个 Completed 事件,您可以使用它来标识转换的结束。

There isn't a started event but you could trigger something equivalent to this before you navigate to the page with the transition.没有启动事件,但您可以在导航到带有转换的页面之前触发与此等效的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM