TryGetVisualStateGroup() public static method

This method tries to get the named VisualStateGroup for the dependency object. The provided object's ImplementationRoot will be looked up in this call.
public static TryGetVisualStateGroup ( DependencyObject dependencyObject, string groupName ) : VisualStateGroup
dependencyObject DependencyObject The dependency object.
groupName string The visual state group's name.
return VisualStateGroup
Beispiel #1
0
        /// <summary>
        /// Should be called by the parent control before the base
        /// OnApplyTemplate method is called.
        /// </summary>
        public void BeforeOnApplyTemplate()
        {
            if (UsesClosingVisualState)
            {
                // Unhook the event handler for the popup closed visual state group.
                // This code is used to enable visual state transitions before
                // actually setting the underlying Popup.IsOpen property to false.
                VisualStateGroup groupPopupClosed = VisualStates.TryGetVisualStateGroup(Parent, VisualStates.GroupPopup);
                if (null != groupPopupClosed)
                {
                    groupPopupClosed.CurrentStateChanged -= OnPopupClosedStateChanged;
                    UsesClosingVisualState = false;
                }
            }

            if (Popup != null)
            {
                Popup.Closed -= Popup_Closed;
            }
        }
        /// <summary>
        /// Builds the visual tree for the Picker control when a new template is
        /// applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // Unhook the event handler for the popup closed visual state group.
            // This code is used to enable visual state transitions before
            // actually setting the underlying Popup.IsOpen property to false.
            VisualStateGroup groupPopupClosed = VisualStates.TryGetVisualStateGroup(this, VisualStates.GroupPopup);

            if (null != groupPopupClosed)
            {
                groupPopupClosed.CurrentStateChanged -= OnPopupClosedStateChanged;
                _popupClosedVisualState = false;
            }

            base.OnApplyTemplate();

            bool dropDownOpenInitialValue = IsDropDownOpen;

            // todo: having the group does not mean having the closed state, which seems to be assumed.
            groupPopupClosed = VisualStates.TryGetVisualStateGroup(this, VisualStates.GroupPopup);
            if (null != groupPopupClosed)
            {
                groupPopupClosed.CurrentStateChanged += OnPopupClosedStateChanged;
                _popupClosedVisualState = true;
            }

            // Set the template parts. Individual part setters remove and add
            // any event handlers.
            DropDownToggleButton = GetTemplateChild(ElementDropDownToggleName) as ToggleButton;
            DropDownPopup        = GetTemplateChild(ElementPopupName) as Popup;

            Interaction.OnApplyTemplateBase();

            // initialization has finished, we have all the necessary references
            // possibly open DropDown.
            if (dropDownOpenInitialValue)
            {
                IsDropDownOpen = true;
            }
        }
Beispiel #3
0
        /// <summary>
        ///     TransitionProperty property changed handler.
        /// </summary>
        /// <param name="d">TransitioningContentControl that changed its Transition.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnTransitionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var source        = (TransitioningContentControl)d;
            var oldTransition = e.NewValue as string;
            var newTransition = e.NewValue as string;

            if (source.IsTransitioning)
            {
                source.AbortTransition();
            }

            // find new transition
            Storyboard newStoryboard = source.GetStoryboard(newTransition);

            // unable to find the transition.
            if (newStoryboard == null)
            {
                // could be during initialization of xaml that presentationgroups was not yet defined
                if (VisualStates.TryGetVisualStateGroup(source, PresentationGroup) == null)
                {
                    // will delay check
                    source.CurrentTransition = null;
                }
                else
                {
                    // revert to old value
                    source.SetValue(TransitionProperty, oldTransition);

                    throw new ArgumentException(
                              string.Format(CultureInfo.CurrentCulture,
                                            Properties.Resources.TransitioningContentControl_TransitionNotFound, newTransition));
                }
            }
            else
            {
                source.CurrentTransition = newStoryboard;
            }
        }