private void BringToLife() { if (_dt == null && _hasImageLoaded) { _dt = new DispatcherTimer(); OrganicInterval(); _dt.Tick += OnTick; double d = Random.NextDouble(); double delayInSeconds = 3 * d; // 0 to 9 seconds. delayInSeconds *= 2.1; // multiply/space-out #if DEBUG_LIVE_TILES Debug.WriteLine("__LIVE_TILE starting: " + ImageSource); #endif IntervalDispatcher.BeginInvoke( TimeSpan.FromSeconds(delayInSeconds), () => { var dt = _dt; if (dt != null) { dt.Start(); } }); } }
protected override void OnContentPresenterLoaded(RoutedEventArgs e) { Debug("OnContentPresenterLoaded"); base.OnContentPresenterLoaded(e); if (_state == LoadingState.StartingLoad || _state == LoadingState.ContentPresenterUnloaded) { // Check for the underlying ready state. UpdateState(LoadingState.ContentPresenterLoaded); // DIFFERENCE: // My original implementation had a minimum loading time. // If the time had not elapsed, this would invoke again. // The reason was probably to allow the DataContext and // visuals to all be realized enough to compute whether // it was a "smart" set of content or not. // CONSIDER: // Perhaps a DelayDispatchTimer here or similar. // TODO: Could make this configurable... IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(.1), AnalyzeOrTransition); } else { var x = _state; } }
private void UpdateState(LoadingState state) { Debug("New State: " + state.ToString()); if (_state != state) { _state = state; switch (state) { case LoadingState.Constructed: break; case LoadingState.StartingLoad: if (!HasContentLoaded) { if (LoadingDisplayOffset.TotalSeconds == 0.0 && _state != LoadingState.Failed) { Debug("Offset seconds of 0, going to loading state"); UpdateCover(CoverState.Loading); } else { // UpdateCover(CoverState.Blank); // ? is this necessary ? IntervalDispatcher.BeginInvoke(LoadingDisplayOffset, StartingLoadDelayExpired); } } break; case LoadingState.TemplateApplied: UpdateCover(CoverState.Blank); System.Diagnostics.Debug.Assert(IsCovered == true); break; case LoadingState.Unknown: break; case LoadingState.ContentUncovered: UpdateCover(CoverState.Blank); break; case LoadingState.ContentPresenterLoaded: case LoadingState.ContentPresenterUnloaded: case LoadingState.Failed: case LoadingState.ReadyToUncover: break; case LoadingState.TimedOut: UpdateCover(CoverState.Timeout); break; default: //#if DEBUG // throw new InvalidOperationException(); //#endif break; } } }
private void UpdateItems() { if (!_templateApplied || DesignerProperties.IsInDesignTool) { return; } if (_height < 1) { Dispatcher.BeginInvoke(UpdateItems); return; } _itemsInFirstScreen = (_height / MinimumItemHeight) * 1.8; // VOODOO MAGIC. // Moved from 1.3 to 1.8 right before my 2.2 release. StopRenderingQueue(); var oldGroupItems = new List <ItemGroup>(_groupItems); _groupItems.Clear(); int totalItems = -1; if (ItemsSource != null) { var list = (IList)ItemsSource; if (IsFlatList) { var alist = new List <IList>(1); var blist = list; alist.Add(blist); list = alist; } int groupCount = list.Count; if (groupCount <= 0) { ShowHideIsEmpty(false); } // For long lists of data... int actualItemCount = 0; for (int i = 0; i < list.Count; ++i) { IList x = list[i] as IList; if (x != null) { actualItemCount += x.Count; } } double approximateVisualLoadPoint = actualItemCount * .45; // WAS PREVIOUSLY: .66; in my voodoo magic... if (approximateVisualLoadPoint > _itemsInFirstScreen) { // Debug.WriteLine("Overriding the visual load point to be " + approximateVisualLoadPoint + " over " + _itemsInFirstScreen); _itemsInFirstScreen = approximateVisualLoadPoint; } for (int i = 0; i < list.Count; ++i) { //ItemGroup oldGroupAtIndex = null; //if (oldGroupItems.Count > i) //{ //oldGroupAtIndex = oldGroupItems[i]; //Debug.WriteLine("Was an old group, too."); //} var group = GetOrCreateGroup(list[i], i); _groupItems.Add(group); // if (oldGroupAtIndex != null && // oldGroupAtIndex.Name != group.Name) var groupItems = list[i] as IList; #if DEBUG if (groupItems == null) { throw new NotSupportedException("Must be an IList. " + list[i].ToString()); } #endif UpdateMappings(group, groupItems, ref totalItems); #if DEBUG_GIC Debug.WriteLine("totalItems is now: *** " + totalItems); #endif } if (groupCount == 0 || totalItems < 0) // was: totalItems <= to 0, but since it started at -1, // that meant 1 item was nothing. { #if DEBUG_GIC Debug.WriteLine("GC 0 and TC 0 so done loading now."); #endif ShowHideIsEmpty(false); IsLoadComplete = true; var isend = ItemsSource as ISendLoadComplete; if (isend != null && !isend.IsLoadComplete) { #if DEBUG_GIC Debug.WriteLine("It's an isend but not ready."); #endif } else if (isend != null) { #if DEBUG_GIC Debug.WriteLine("It's an isend and ready!"); #endif } } else { // Display! ...... //IsLoadComplete = true; _haveItems = true; ShowHideIsEmpty(true); if (!_myPageLoading) { _myPageLoading = true; } } } else { // Want to eliminate the flicker the first time this pops up. IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(0.25), EvaluateWhetherNullStill); #if DEBUG_GIC Debug.WriteLine("ItemsSource is now null."); #endif } List <ItemGroup> groupsToRemove = new List <ItemGroup>(); for (int gi = 0; gi < _groupItems.Count; ++gi) { var group = _groupItems[gi]; #if DEBUG_GIC Debug.WriteLine("*" + group.Name + " (" + group.Items.Count + ")"); #endif if (group.Items.Count == 0) { // Hide the group! From a logic standpoint, this should have been detected above. #if DEBUG_GIC Debug.WriteLine("Hide the group! From a logic standpoint..." + group); #endif groupsToRemove.Add(group); } } foreach (var ii in oldGroupItems) { // SLOW. if (_groupItems.Contains(ii)) { continue; } #if DEBUG_GIC Debug.WriteLine("Slow hide the group! " + ii); #endif groupsToRemove.Add(ii); } foreach (var g in groupsToRemove) { #if DEBUG_GIC Debug.WriteLine("Removing a group that was not in the new items source."); #endif g.RemoveGroup(this); if (_groups.ContainsValue(g)) { foreach (var grp in _groups) { if (grp.Value == g) { var key = grp.Key; _groups.Remove(key); break; } } } } StartRenderingQueue(); }