/// <summary> /// Builds the visual tree for the AccordionItem control when a new /// template is applied. /// </summary> protected override void OnApplyTemplate() { base.OnApplyTemplate(); ExpanderButton = GetTemplateChild(ElementExpanderButtonName) as AccordionButton; ExpandSite = GetTemplateChild(ElementExpandSiteName) as ExpandableContentControl; if (VisualTreeHelper.GetChildrenCount(this) > 0) { FrameworkElement root = VisualTreeHelper.GetChild(this, 0) as FrameworkElement; if (root != null) { ExpandStoryboard = (from stategroup in VisualStateManager.GetVisualStateGroups(root) where stategroup.Name == VisualStates.GroupExpansion from state in stategroup.States where state.Name == VisualStates.StateExpanded select state.Storyboard).FirstOrDefault(); CollapseStoryboard = (from stategroup in (VisualStateManager.GetVisualStateGroups(root)) where stategroup.Name == VisualStates.GroupExpansion from state in (stategroup.States) where state.Name == VisualStates.StateCollapsed select state.Storyboard).FirstOrDefault(); ExpandStoryboard.Begin(); } else { ExpandStoryboard = null; CollapseStoryboard = null; } } _interaction.OnApplyTemplateBase(); UpdateVisualState(false); // the UpdateVisualState will not set the expand or collapse state. if (IsSelected) { Schedule(AccordionAction.Expand); } else { Schedule(AccordionAction.Collapse); } }
/// <summary> /// Create the storyboard for the collapsed state /// </summary> private void GotoCollapsedState(bool useTransitions = true) { ExpandStoryboard.Stop(); if (useTransitions) { MenuAnimation.From = (_menuHeight.Equals(Double.NaN)) ? GetDesiredControlHeight(MapMenuControl) : _menuHeight; MenuAnimation.To = 0; ExpandStoryboard.Begin(); } else { MapMenuControl.Height = 0; } }