/// <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>
        /// 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);
            }
        }
        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);
        }
 /// <summary>
 /// This event handler gets called as soon as a flip tile is removed from the visual tree.
 /// Any existing reference of this flip tile is eliminated from the service singleton.
 /// </summary>
 /// <param name="sender">The flip tile.</param>
 /// <param name="e">The event information.</param>
 void FlipTile_Unloaded(object sender, RoutedEventArgs e)
 {
     FlipTileService.FinalizeReference(this);
 }
 /// <summary>
 /// This event handler gets called as soon as a flip tile is added to the visual tree.
 /// A reference of this flip tile is passed on to the service singleton.
 /// </summary>
 /// <param name="sender">The flip tile.</param>
 /// <param name="e">The event information.</param>
 void FlipTile_Loaded(object sender, RoutedEventArgs e)
 {
     FlipTileService.InitializeReference(this);
 }