Пример #1
0
        /// <summary>
        /// Tries to match the selector with a control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="subscribe">
        /// Whether the match should subscribe to changes in order to track the match over time,
        /// or simply return an immediate result.
        /// </param>
        /// <returns>A <see cref="SelectorMatch"/>.</returns>
        public SelectorMatch Match(IStyleable control, bool subscribe = true)
        {
            List <IObservable <bool> > inputs = new List <IObservable <bool> >();
            Selector selector = this;

            while (selector != null)
            {
                if (selector.InTemplate && control.TemplatedParent == null)
                {
                    return(SelectorMatch.False);
                }

                var match = selector.Evaluate(control, subscribe);

                if (match.ImmediateResult == false)
                {
                    return(match);
                }
                else if (match.ObservableResult != null)
                {
                    inputs.Add(match.ObservableResult);
                }

                selector = selector.MovePrevious();
            }

            if (inputs.Count > 0)
            {
                return(new SelectorMatch(StyleActivator.And(inputs)));
            }
            else
            {
                return(SelectorMatch.True);
            }
        }