示例#1
0
        private void Calculate(bool allow = false)
        {
            if (!allow)
            {
                if (!update)
                {
                    return;
                }
            }
            update = false;
            if (element == null)
            {
                return;
            }
            // make changes on UI thread
            _dispatcher.Dispatch(() =>
            {
                switch (Direction)
                {
                case Directions.Back:
                    element.Visibility = CalculateBackVisibility(Frame);
                    break;

                case Directions.Forward:
                    element.Visibility = CalculateForwardVisibility(Frame);
                    break;
                }
            });
        }
示例#2
0
        private void Calculate()
        {
            // just in case
            if (element == null)
            {
                return;
            }

            // make changes on UI thread
            _dispatcher.Dispatch(() =>
            {
                switch (Direction)
                {
                case Directions.Back:
                    {
                        element.Visibility = CalculateBackVisibility(Frame);
                        break;
                    }

                case Directions.Forward:
                    {
                        element.Visibility = CalculateForwardVisibility(Frame);
                        break;
                    }
                }
            });
        }
        public void Load()
        {
            if (IsLoaded)
            {
                return;
            }

            var loadDataTask = LoadData();

            loadDataTask.ContinueWith(x =>
            {
                Loaded?.Invoke(this, EventArgs.Empty);
            }, TaskContinuationOptions.OnlyOnFaulted);

            loadDataTask.ContinueWith(async x =>
            {
                var people = x.Result.ToList();

                await LoadRanking(people).ConfigureAwait(false);

                people = people.Where(p => p.Stats != null).ToList();

                var portraitsDatas = LoadImages(people)
                                     .ConfigureAwait(false)
                                     .GetAwaiter()
                                     .GetResult()
                                     .ToList();

                var images = new Dictionary <int, BitmapImage>();

                for (int i = 0; i < portraitsDatas.Count; i++)
                {
                    var portraitsData = portraitsDatas[i];
                    var i1            = i;
                    _dispatcherWrapper.Dispatch(() =>
                    {
                        var image  = portraitsData.GetBitmapImage();
                        images[i1] = image;
                    });
                }

                //List<PersonViewModel> sortedPeople = new List<PersonViewModel>();

                foreach (var personToAdd in people)
                {
                    var personViewModel = new PersonViewModel {
                        Person = personToAdd
                    };
                    People.Add(personViewModel);

                    if (personToAdd.ImageInfo == null)
                    {
                        continue;
                    }

                    _dispatcherWrapper.Dispatch(() =>
                    {
                        var image             = images[personToAdd.ImageInfo.Image];
                        personViewModel.Image = image;
                        personViewModel.Clip  = new RectangleGeometry
                        {
                            Rect = new Rect(personToAdd.ImageInfo.Left, 0, 95, 100)
                        };
                        personViewModel.Left = -personToAdd.ImageInfo.Left;
                    });
                }

                IsLoaded = true;
                Loaded?.Invoke(this, EventArgs.Empty);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }