private void CreateNativeGroupListeners()
        {
            foreach (var visualStateGroup in EnumerateVisualStateGroups())
            {
                VisualGroupListener groupListener = null;

                foreach (VisualState visualState in visualStateGroup.States)
                {
                    var stateListeners = FindListenerCollection(visualState.Name);

                    if (stateListeners == null)
                    {
                        continue;
                    }

                    if (groupListener == null)
                    {
                        groupListener = new VisualGroupListener();
                    }

                    groupListener.AddStateListenersCollection(stateListeners);
                }

                if (groupListener == null)
                {
                    continue;
                }

                _visualStateGroupObservers.Add(new VisualStateGroupObserver(visualStateGroup, groupListener));
            }
        }
Example #2
0
        public VisualStateGroupObserver(VisualStateGroup visualGroup, VisualGroupListener groupListener) : base(groupListener)
        {
            _visualGroup  = visualGroup;
            _visualStates = new HashSet <string>(visualGroup.States.Cast <VisualState>().Select(s => s.Name), StringComparer.OrdinalIgnoreCase);
            _visualGroup.CurrentStateChanged += VisualGroupOnCurrentStateChanged;

            Update();
        }
        private void CreateGroupObservers()
        {
            var implementationRoot = ImplementationRoot;

            if (implementationRoot == null)
            {
                return;
            }

            var advisor           = implementationRoot as IVisualStateManagerAdvisor;
            var visualStateGroups = advisor != null ? advisor.VisualStateGroups : VisualStateManager.GetInstance(implementationRoot)?.Groups;

            if (visualStateGroups == null)
            {
                return;
            }

            foreach (var stateGroup in visualStateGroups)
            {
                if (FindGroupObserver(stateGroup.Name) != null)
                {
                    continue;
                }

                var visualGroupListener = new VisualGroupListener();

                foreach (var visualState in stateGroup.States)
                {
                    var listeners = FindListenerCollection(visualState.Name) ?? new VisualStateListenerCollection(visualState.Name);

                    // Template changed. Keep previous visual states.
                    if (listeners.IsActive)
                    {
                        visualGroupListener.GoToState(listeners.StateName, false);
                    }

                    visualGroupListener.AddStateListenersCollection(listeners);
                }

                _visualStateGroupObservers.Add(new DelegateVisualStateGroupObserver(stateGroup.Name, stateGroup.States.Select(v => v.Name), visualGroupListener));
            }
        }
        private VisualStateListenerCollection GetListenerCollection(string name, bool create)
        {
            var listenerCollection = FindListenerCollection(name);

            if (listenerCollection == null && create == false)
            {
                return(null);
            }

            var groupObserver = FindGroupObserverByStateName(name);

            if (groupObserver != null)
            {
                listenerCollection = groupObserver.GroupListener.GetListenerCollection(name, create);
            }

            if (listenerCollection != null)
            {
                _stateListenerCollections.Add(listenerCollection);
                return(listenerCollection);
            }

            listenerCollection = new VisualStateListenerCollection(name);
            _stateListenerCollections.Add(listenerCollection);

            var visualStateGroup = EnumerateVisualStateGroups().SingleOrDefault(g => g.States.Cast <VisualState>().Any(s => string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase)));

            if (visualStateGroup == null)
            {
                return(listenerCollection);
            }

            var groupListener = new VisualGroupListener();

            groupListener.AddStateListenersCollection(listenerCollection);
            groupObserver = new VisualStateGroupObserver(visualStateGroup, groupListener);
            _visualStateGroupObservers.Add(groupObserver);

            return(listenerCollection);
        }
Example #5
0
 protected VisualStateGroupObserverBase(VisualGroupListener groupListener)
 {
     GroupListener = groupListener;
 }
Example #6
0
 public DelegateVisualStateGroupObserver(string groupName, IEnumerable <string> states, VisualGroupListener groupListener) : base(groupListener)
 {
     _states = states.ToList();
     Name    = groupName;
 }