简体   繁体   中英

How to Determine Which Pivot Item is Navigated To Most Often

I am using a Pivot Control which contains 5 Pivot Items on a page. The user can only swipe right or left to get to these, but from the starting pivot, index = 0, I'd like to be able to determine which direction, and how far in that direction, a user generally goes. Since each of my pivots is loading several pieces of data, and the user can swipe either left or right from the starting index, my ultimate goal is to determine how often a user goes in either direction, and how far, and load those pivot items first. For Instance, If my pivots are

MainPage.xaml

<phone:Pivot x:Name="myPivot">
    <phone:PivotItem Header="one"/>
    <phone:PivotItem Header="two"/>
    <phone:PivotItem Header="three"/>
    <phone:PivotItem Header="four"/>
    <phone:PivotItem Header="five"/>
</phone:Pivot>

MainPage.xaml.cs

private async void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        await RenderAsync();
    }

private async Task RenderAsync()
    {
        if (!Busy)
        {
            Busy = true;

            int side = 136;

            try
            {
                using (Bitmap bitmap = await App.Model.RenderBitmapAsync(side))
                {
                    if (Settings.LoadDynamically.Value == false)
                    {
                        await RenderAsync(bitmap, side, App.Model.One, OneWrapPanel);
                        await RenderAsync(bitmap, side, App.Model.Two, TwoWrapPanel);
                        await RenderAsync(bitmap, side, App.Model.Three, ThreeWrapPanel);
                        await RenderAsync(bitmap, side, App.Model.Four, FourWrapPanel);
                        await RenderAsync(bitmap, side, App.Model.Fiv, FiveWrapPanel);
                    }
                    else
                    {
                        //Custom order goes here, load best order
                    }

                }
            }
            catch (Exception)
            {
                NavigationService.GoBack();
            }

            Busy = false;
        }
    }

where the first pivot item is index of 0 and the fifth is index of 4, from the first pivot I'd like to be able to determine how many times the user navigates to pivot 5 (to the left) and to pivot two (the right). From here, I'd again like to know how many times the user keeps going in that direction. So if the user went to 5 and then 4, and also from two to three. Once this data is gathered, I'd like to be able to determine, possibly by setting some sort of weight for each situation, the best order to load each pivot item.

There is no other way, I think. It's very easy:

private void appPivot_LoadedPivotItem(object sender, PivotItemEventArgs e)
{
  startUse = DateTime.Now;
}

private void appPivot_UnloadingPivotItem(object sender, PivotItemEventArgs e)
{
  TimeSpan pivotUsage = DateTime.Now - startUse;
  // Save it somewhere regarding to SelectedPivotItem
}

But changing the order isn't recommended in the metro design guidance(as I remember), however I personally think that it's a good idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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