BaconographyWP8.Common.RedditViewPivotControl.OnLoadingPivotItem C# (CSharp) Метод

OnLoadingPivotItem() защищенный Метод

protected OnLoadingPivotItem ( PivotItem item ) : void
item PivotItem
Результат void
        protected override async void OnLoadingPivotItem(PivotItem item)
        {
            //since this is going to take a non trivial amount of time we need to prevent
            //any future loads from conflicting with what we're doing
            //by taking an always increasing id we can check aginst it prior to continuing
            //and implement a sort of cancel.

            //this has the added side effect of making super rapid transitions of the pivot nearly free
            //since no one pivot will be the current one for more then a few hundred milliseconds

            using (_suspendableWorkQueue.HighValueOperationToken)
            {
                var loadIdAtStart = ++inflightLoadId;
                inflightLoad = item;

                base.OnLoadingPivotItem(item);

                _viewModelContextService.PushViewModelContext(item.DataContext as ViewModelBase);

                if (item.Content is RedditView)
                {
                    return;
                }

                var imageControl = item.Content as Image;

                if (imageControl != null)
                    await Task.Delay(400);

                if (loadIdAtStart != inflightLoadId)
                    return;

                var madeControl = MapViewModel(item.DataContext as ViewModelBase);

                if (imageControl != null)
                    await Task.Yield();

                if (loadIdAtStart != inflightLoadId)
                    return;

                madeControl.DataContext = item.DataContext as ViewModelBase;
                if (imageControl != null)
                    await Task.Yield();

                if (loadIdAtStart != inflightLoadId)
                    return;

                if (imageControl != null)
                    imageControl.Source = null;

                item.Content = madeControl;
                madeControl.LoadWithScroll();
            }
        }