/// <summary>
        /// RevealModeProperty property changed handler.
        /// </summary>
        /// <param name="d">ExpandableContentControl that changed its RevealMode.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnRevealModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ExpandableContentControl source = (ExpandableContentControl)d;
            ExpandDirection          value  = (ExpandDirection)e.NewValue;

            if (value != ExpandDirection.Down &&
                value != ExpandDirection.Left &&
                value != ExpandDirection.Right &&
                value != ExpandDirection.Up)
            {
                // revert to old value
                source.RevealMode = (ExpandDirection)e.OldValue;

                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    "Properties.Resources.Expander_OnExpandDirectionPropertyChanged_InvalidValue",
                    value);
                throw new ArgumentException(message, "e");
            }

            // set the non-reveal dimension
            source.SetNonRevealDimension();

            // calculate the reveal dimension
            source.SetRevealDimension();
        }
        /// <summary>
        /// TargetSizeProperty property changed handler.
        /// </summary>
        /// <param name="d">ExpandableContentControl that changed its TargetSize.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnTargetSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ExpandableContentControl source = (ExpandableContentControl)d;
            Size value = (Size)e.NewValue;

            // recalculate percentage based on this new targetsize.
            // for instance, percentage was at 1 and width was 100. Now width was changed to 200, this means
            // that the percentage needs to be set to 0.5 so that a reveal animation can be started again.

            source.RecalculatePercentage(value);
        }
        /// <summary>
        /// ContentTargetSizeProperty property changed handler.
        /// </summary>
        /// <param name="d">AccordionItem that changed its ContentTargetSize.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnContentTargetSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AccordionItem source     = (AccordionItem)d;
            Size          targetSize = (Size)e.NewValue;

            if (!source._allowedToWriteContentTargetSize)
            {
                // revert to old value
                source.ContentTargetSize = (Size)e.OldValue;

                throw new InvalidOperationException("Properties.Resources.AccordionItem_InvalidWriteToContentTargetSize");
            }

            // Pass the value to the expandSite
            // This is done explicitly so an animation action can be scheduled
            // deterministicly.
            ExpandableContentControl expandSite = source.ExpandSite;

            if (expandSite != null && !expandSite.TargetSize.Equals(targetSize))
            {
                expandSite.TargetSize = targetSize;
                if (source.IsSelected)
                {
                    if (source.ParentAccordion != null && source.ParentAccordion.IsResizing)
                    {
                        // if the accordion is resizing, this item should snap immediately
                        expandSite.Percentage = 1;
                    }
                    else
                    {
                        // otherwise schedule the resize
                        source.Schedule(AccordionAction.Resize);
                    }
                }
            }
        }
        /// <summary>
        /// PercentageProperty property changed handler.
        /// </summary>
        /// <param name="d">Page that changed its Percentage.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnPercentagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ExpandableContentControl source = (ExpandableContentControl)d;

            source.SetRevealDimension();
        }