private static void OnCurrentPlaceholderStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            if (args != null && (args.NewValue != args.OldValue))
            {
                PlaceholderState state = (PlaceholderState)args.NewValue;

                //initialise
                if (layoutManager == null)
                {
                    layoutManager = (new PlaceholderStateManager(d as Grid)
                    {
                        PlaceholderItems = GetPlaceholderStateItems(d) as IList <PlaceholderStateItem>
                    });
                }


                if (layoutManager != null)
                {
                    // set the layout to loading Template.
                    if (state == PlaceholderState.Loading)
                    {
                        layoutManager.SwitchToPlaceholderTemplate(d as Grid, state);
                    }
                    else if (state == PlaceholderState.NoState)
                    {
                        layoutManager.SwitchToAppContent(d as Grid);
                    }
                }
            }
        }
        public async void LoadDifferentStates()
        {
            CurrentState = PlaceholderState.Loading;

            await Task.Delay(TimeSpan.FromSeconds(5));

            CurrentState = PlaceholderState.NoState;
        }
Exemple #3
0
        protected void UpdateScores()
        {
            // don't display any scores or placeholder until the first Scores_Set has been called.
            // this avoids scope changes flickering a "no scores" placeholder before initialisation of song select is finished.
            if (!scoresLoadedOnce)
            {
                return;
            }

            getScoresRequest?.Cancel();
            getScoresRequest = null;

            pendingUpdateScores?.Cancel();
            pendingUpdateScores = Schedule(() =>
            {
                if (api?.IsLoggedIn != true)
                {
                    PlaceholderState = PlaceholderState.NotLoggedIn;
                    return;
                }

                PlaceholderState = PlaceholderState.Retrieving;
                loading.Show();

                getScoresRequest = FetchScores(scores => Schedule(() =>
                {
                    Scores           = scores;
                    PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
                }));

                if (getScoresRequest == null)
                {
                    return;
                }

                getScoresRequest.Failure += e => Schedule(() =>
                {
                    if (e is OperationCanceledException)
                    {
                        return;
                    }

                    PlaceholderState = PlaceholderState.NetworkFailure;
                });

                api.Queue(getScoresRequest);
            });
        }
        internal void SwitchToPlaceholderTemplate(Grid layout, PlaceholderState placeholderState)
        {
            // save original content if not already done
            if (_previousState == PlaceholderState.NoState)
            {
                _savedContent = layout.Children.ToList();
            }

            _previousState = placeholderState;

            //get PlaceholderStateItem
            var          template     = GetPlaceholderTemplate(placeholderState);
            int          repeat       = template.RepeatItem;
            DataTemplate itemTemplate = template.PlaceholderTemplate;

            //clear UI
            layout.Children.Clear();

            //if reapet = 1 or we can find an item template then only repeat this once
            if (repeat == 1 || itemTemplate == null)
            {
                layout.Children.Add(template);
            }
            else
            {
                var repeatItemsSource = new List <int>();
                for (int i = 0; i < repeat; i++)
                {
                    repeatItemsSource.Add(repeat);
                }

                var ls = new ListView();
                ls.SelectionMode = ListViewSelectionMode.None;
                ls.ShowsScrollingPlaceholders = false;
                //ls.CanBeScrollAnchor = false;

                //insert template
                ls.ItemTemplate = itemTemplate;
                ls.ItemsSource  = repeatItemsSource;

                layout.Children.Add(ls);
            }
        }
        internal void SwitchToAppContent(Grid g)
        {
            _previousState = PlaceholderState.NoState;

            //clear placeholder state
            g.Children.Clear();

            // Put the original content back in.
            foreach (var item in _savedContent)
            {
                try
                {
                    g.Children.Add(item);
                }
                catch (System.Exception)
                {
                }
            }
        }
Exemple #6
0
 public void SetRetrievalState(PlaceholderState state)
 {
     PlaceholderState = state;
 }
        private PlaceholderStateItem GetPlaceholderTemplate(PlaceholderState placeholderState)
        {
            var template = PlaceholderItems.Where(a => a.StateItemKey == placeholderState).FirstOrDefault();

            return(template);
        }
 public static void SetCurrentPlaceholderState(UIElement element, PlaceholderState value)
 {
     element.SetValue(CurrentPlaceholderStateProperty, value);
 }