Пример #1
0
        private ExpressionObserver CreateFindAncestorObserver(
            IStyledElement target,
            RelativeSource relativeSource,
            string path,
            bool enableDataValidation)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            IObservable <object> controlLocator;

            switch (relativeSource.Tree)
            {
            case TreeType.Logical:
                controlLocator = ControlLocator.Track(
                    (ILogical)target,
                    relativeSource.AncestorLevel - 1,
                    relativeSource.AncestorType);
                break;

            case TreeType.Visual:
                controlLocator = VisualLocator.Track(
                    (IVisual)target,
                    relativeSource.AncestorLevel - 1,
                    relativeSource.AncestorType);
                break;

            default:
                throw new InvalidOperationException("Invalid tree to traverse.");
            }

            return(new ExpressionObserver(
                       controlLocator,
                       path,
                       enableDataValidation));
        }
Пример #2
0
        protected ExpressionObserver CreateFindAncestorObserver(
            IStyledElement target,
            RelativeSource relativeSource,
            ExpressionNode node)
        {
            _ = target ?? throw new ArgumentNullException(nameof(target));

            IObservable <object?> controlLocator;

            switch (relativeSource.Tree)
            {
            case TreeType.Logical:
                controlLocator = ControlLocator.Track(
                    (ILogical)target,
                    relativeSource.AncestorLevel - 1,
                    relativeSource.AncestorType);
                break;

            case TreeType.Visual:
                controlLocator = VisualLocator.Track(
                    (IVisual)target,
                    relativeSource.AncestorLevel - 1,
                    relativeSource.AncestorType);
                break;

            default:
                throw new InvalidOperationException("Invalid tree to traverse.");
            }

            return(new ExpressionObserver(
                       controlLocator,
                       node,
                       null));
        }