示例#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));
        }
示例#3
0
 protected override void StartListeningCore(WeakReference <object> reference)
 {
     if (reference.TryGetTarget(out object target) && target is IVisual visual)
     {
         _subscription = VisualLocator.Track(visual, _level, _ancestorType).Subscribe(ValueChanged);
     }