简体   繁体   English

优化Pivot Control Windows Phone 8

[英]Optimising Pivot Control windows phone 8

case 1: 情况1:

I have a Pivot Control with 3 Pivot Items, and each pivot item will be filled with data(from server) once it gets focus for the first time. 我有一个带有3个数据透视项的数据透视控件,并且每个数据透视项在第一次获得焦点时都将充满数据(来自服务器)。

Now, It makes lot of delay when I navigate back from some other page to this Pivot Page. 现在,当我从其他页面导航回到该数据透视页面时,会产生很多延迟。 How to optimise it and reduce the delay? 如何优化它并减少延迟? Even I cannot show a ProgressBar while Navigating back to this page. 导航回此页面时,即使我也无法显示ProgressBar。

Case 2: 情况2:

I have a ListView with more items, say 150, On selection of an item I need a show detailed description of the selectedItem, and it should be swipeable so that the user can see the next records in the same description page. 我有一个包含更多项目的ListView,例如150,选择一个项目时,我需要显示selectedItem的详细描述,并且它应该是可滑动的,以便用户可以在同一描述页面中看到下一条记录。

Right now, i am using Pivot Page and Binding the Items to the ItemsSource Property, and it creates even lot more delay (of 10 seconds) while navigating to the Pivot Page and Navigating from the Pivot Page. 现在,我正在使用“数据透视页面”并将项目绑定到ItemsSource属性,并且导航到“数据透视页面”并从“数据透视页面”导航时会产生更多的延迟(10秒)。

How to get rid of that delay? 如何摆脱这种延迟?

Help me. 帮我。 Thanks. 谢谢。

Use LongListSelector (WP8) or ListView (WP8.1) as items holder on first page. 使用LongListSelector (WP8)或ListView (WP8.1)作为首页上的项目持有人。 It has UI virtualization, so no matter how much items will be on a page, only items on screen will be rendered. 它具有UI虚拟化,因此无论页面上有多少项目,都只会呈现屏幕上的项目。 It must solve your case 1 delay. 它必须解决您的case 1延迟。 If doesn't - the problem is in page 2 destroying. 如果不是,则问题出在第2页中。

You details screen approach is completely wrong. 您详细信息的屏幕处理方法是完全错误的。 Pivot is create for other purposes and its not recommended to hold more than 5 items inside. Pivot是为其他目的而创建的,不建议在其中容纳5个以上的项目。

So you need: 因此,您需要:

  1. Create page for displaying one item and bind DataContext to LayoutRoot 创建用于显示一项的页面并将DataContext绑定到LayoutRoot
  2. Add ManipulationCompleted event handler to LayoutRoot and check if swipe has place ManipulationCompleted事件处理程序添加到LayoutRoot并检查是否有滑动
  3. Update DataContext to prev or next item. DataContext更新为上一个或下一个项目。 This will update data displayed on the screen 这将更新屏幕上显示的数据
  4. When this will work, create animations to smooth transition of current page to left and right: 在这种情况下,请创建动画以平滑当前页面向左和向右的过渡:
    • when user move finger on a phone - move page left and right to the same offset 当用户在电话上移动手指时-将页面左右移动相同的偏移量
    • when user leave finger - call animation to complete swipe 当用户离开手指时-调用动画以完成滑动
    • when animation completed (page out of the screen), update DataContext and call animation to bring new item from other side of the screen 动画完成时(屏幕外的页面),更新DataContext并调用动画以从屏幕的另一侧带来新的项目

This will replicate Pivot behavior but with no memory consumption for unvisible items 这将复制“ Pivot行为,但不会消耗不可见项的内存

UPD: UPD:

Step 4 implementation: 第4步实施:

private void LayoutRoot_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
    (LayoutRoot.RenderTransform as CompositeTransform).TranslateX += e.DeltaManipulation.Translation.X;
}

private void LayoutRoot_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
    if (e.TotalManipulation.Translation.X + e.FinalVelocities.LinearVelocity.X < -100)
    {
        if (current < Count - 1)
        {
            //slide to next item
            current++;
        }
        else
        {
            //no next item - slide back
        }
    }
    else if (e.TotalManipulation.Translation.X + e.FinalVelocities.LinearVelocity.X > 100)
    {
        if (current > 0)
        {
            // slide to prev item

            current--;
        }
        else
        {
            // no prev item - slide back
        }
    }
    else
    {
        // no swipe - slide back
    }
}

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

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