コード例 #1
0
        /// <summary>
        /// Called when a storyboard finishes.
        /// </summary>
        /// <param name="sender">The AccordionItem that finished a storyboard.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing
        /// the event data.</param>
        /// <remarks>AccordionItem is required to make this call.</remarks>
        private void OnStoryboardFinished(object sender, EventArgs e)
        {
            _isBusyWithAction = false;

            if (ParentAccordion != null)
            {
                ParentAccordion.OnActionFinish(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Starts an action, such as resize, collapse or expand.
        /// </summary>
        internal virtual void StartAction()
        {
            if (ScheduledAction == AccordionAction.None)
            {
                throw new InvalidOperationException(Properties.Resources.AccordionItem_StartAction_InvalidCall);
            }
            Action layoutAction;

            switch (ScheduledAction)
            {
            case AccordionAction.Collapse:
                layoutAction = () =>
                {
                    VisualStateManager.GoToState(this, VisualStates.StateExpanded, false);
                    // We only want to notify the parent that this action is finished when we are done with
                    // the state transition. In SL this is done through OnStoryboardFinished, but the same code
                    // in WPF would result in a corrupted state because OnStoryboardFinished gets called more frequently than expected.
                    // In the WPF case, we make the scheduled action synchornous to ensure the transition is properly done.
#if SILVERLIGHT
                    VisualStateManager.GoToState(this, VisualStates.StateCollapsed, true);
#else
                    if (VisualStateManager.GoToState(this, VisualStates.StateCollapsed, true))
                    {
                        ParentAccordion.OnActionFinish(this);
                    }
#endif
                };
                break;

            case AccordionAction.Expand:
                layoutAction = () =>
                {
                    VisualStateManager.GoToState(this, VisualStates.StateCollapsed, false);
#if SILVERLIGHT
                    VisualStateManager.GoToState(this, VisualStates.StateExpanded, true);
#else
                    if (VisualStateManager.GoToState(this, VisualStates.StateExpanded, true))
                    {
                        ParentAccordion.OnActionFinish(this);
                    }
#endif
                };
                break;

            case AccordionAction.Resize:
                layoutAction = () =>
                {
                    // trigger ExpandedState to run again, by quickly moving to collapsed.
                    // the effect is not noticeable because no layout pass is done.
                    VisualStateManager.GoToState(this, VisualStates.StateExpanded, false);
                    VisualStateManager.GoToState(this, VisualStates.StateCollapsed, false);
#if SILVERLIGHT
                    VisualStateManager.GoToState(this, VisualStates.StateExpanded, true);
#else
                    if (VisualStateManager.GoToState(this, VisualStates.StateExpanded, true))
                    {
                        ParentAccordion.OnActionFinish(this);
                    }
#endif
                };
                break;

            default:
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    Properties.Resources.AccordionItem_StartAction_InvalidAction,
                    ScheduledAction);

                throw new NotSupportedException(message);
            }
            }

            ScheduledAction = AccordionAction.None;
            layoutAction();
        }