/// <summary>
        /// Triggers the transition between visual states.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnSizeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            FlipTile flipTile = (FlipTile)obj;

            // And now we'll update the width and height to match the new size.
            switch (flipTile.Size)
            {
            case TileSize.Default:
                flipTile.Width  = 160;
                flipTile.Height = 160;
                break;

            case TileSize.Small:
                flipTile.Width  = 99;
                flipTile.Height = 99;
                break;

            case TileSize.Medium:
                flipTile.Width  = 210;
                flipTile.Height = 210;
                break;

            case TileSize.Large:
                flipTile.Width  = 432;
                flipTile.Height = 210;
                break;
            }

            flipTile.SizeChanged += OnFlipTileSizeChanged;
            FlipTileService.FinalizeReference(flipTile);
        }
        /// <summary>
        /// Freeze a flip tile.
        /// </summary>
        /// <param name="tile">The flip tile to be frozen.</param>
        public static void FreezeFlipTile(FlipTile tile)
        {
            WeakReference wref = new WeakReference(tile, TrackResurrection);

            AddReferenceToFrozenPool(wref);
            RemoveReferenceFromEnabledPool(wref);
            RemoveReferenceFromStalledPipeline(wref);
        }
        /// <summary>
        /// Remove all references of a flip tile before finalizing it.
        /// </summary>
        /// <param name="tile">The flip tile that is to be finalized.</param>
        internal static void FinalizeReference(FlipTile tile)
        {
            WeakReference wref = new WeakReference(tile, TrackResurrection);

            FlipTileService.RemoveReferenceFromEnabledPool(wref);
            FlipTileService.RemoveReferenceFromFrozenPool(wref);
            FlipTileService.RemoveReferenceFromStalledPipeline(wref);
        }
        /// <summary>
        /// Removes the frozen image from the enabled image pool or the stalled image pipeline.
        /// Adds the non-frozen image to the enabled image pool.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnIsFrozenChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            FlipTile tile = (FlipTile)obj;

            if ((bool)e.NewValue)
            {
                FlipTileService.FreezeFlipTile(tile);
            }
            else
            {
                FlipTileService.UnfreezeFlipTile(tile);
            }
        }
        /// <summary>
        /// Add a reference to a newly instantiated flip tile.
        /// </summary>
        /// <param name="tile">The newly instantiated flip tile.</param>
        internal static void InitializeReference(FlipTile tile)
        {
            WeakReference wref = new WeakReference(tile, TrackResurrection);

            if (tile.IsFrozen)
            {
                AddReferenceToFrozenPool(wref);
            }
            else
            {
                AddReferenceToEnabledPool(wref);
            }

            RestartTimer();
        }
        static void OnFlipTileSizeChanged(object sender, SizeChangedEventArgs e)
        {
            FlipTile flipTile = (FlipTile)sender;

            flipTile.SizeChanged -= OnFlipTileSizeChanged;

            // In order to avoid getting into a bad state, we'll shift the FlipTile
            // back to the Expanded state.  If we were already in the Expanded state,
            // then we'll manually shift the title panel to the right location,
            // since the visual state manager won't do it for us in that case.
            if (flipTile.State != FlipState.Expanded)
            {
                flipTile.State = FlipState.Expanded;
                VisualStateManager.GoToState(flipTile, Expanded, false);
            }

            FlipTileService.InitializeReference(flipTile);
        }