예제 #1
0
 static void OnSearchTermChanged(IAvaloniaObject o, bool changed)
 {
     if (changed)
     {
         ((SearchPane)o).StartSearch(o.GetValue(SearchTermProperty));
     }
 }
예제 #2
0
 private static void RefreshBinding(IAvaloniaObject target, AvaloniaProperty property)
 {
     if (target.GetValue(property) is IBinding binding)
     {
         target.Bind(property, binding);
     }
 }
예제 #3
0
        /// <summary>
        /// Gets the <see cref="BehaviorCollection"/> associated with a specified object.
        /// </summary>
        /// <param name="obj">The <see cref="IAvaloniaObject"/> from which to retrieve the <see cref="BehaviorCollection"/>.</param>
        /// <returns>A <see cref="BehaviorCollection"/> containing the behaviors associated with the specified object.</returns>
        public static BehaviorCollection?GetBehaviors(IAvaloniaObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            BehaviorCollection?behaviorCollection = (BehaviorCollection?)obj.GetValue(BehaviorsProperty);

            if (behaviorCollection == null)
            {
                behaviorCollection = new BehaviorCollection();
                obj.SetValue(BehaviorsProperty, behaviorCollection);

                if (obj is Control control)
                {
                    control.AttachedToVisualTree   -= Control_Loaded;
                    control.AttachedToVisualTree   += Control_Loaded;
                    control.DetachedFromVisualTree -= Control_Unloaded;
                    control.DetachedFromVisualTree += Control_Unloaded;
                }
            }

            return(behaviorCollection);
        }
        /// <summary>
        /// Gets an observable for a <see cref="AvaloniaProperty"/>.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <returns>
        /// An observable which fires immediately with the current value of the property on the
        /// object and subsequently each time the property value changes.
        /// </returns>
        public static IObservable <object> GetObservable(this IAvaloniaObject o, AvaloniaProperty property)
        {
            Contract.Requires <ArgumentNullException>(o != null);
            Contract.Requires <ArgumentNullException>(property != null);

            return(new AvaloniaObservable <object>(
                       observer =>
            {
                EventHandler <AvaloniaPropertyChangedEventArgs> handler = (s, e) =>
                {
                    if (e.Property == property)
                    {
                        observer.OnNext(e.NewValue);
                    }
                };

                observer.OnNext(o.GetValue(property));

                o.PropertyChanged += handler;

                return Disposable.Create(() =>
                {
                    o.PropertyChanged -= handler;
                });
            },
                       GetDescription(o, property)));
        }
예제 #5
0
        protected ExpressionObserver CreateDataContextObserver(
            IAvaloniaObject target,
            ExpressionNode node,
            bool targetIsDataContext,
            object?anchor)
        {
            _ = target ?? throw new ArgumentNullException(nameof(target));

            if (!(target is IDataContextProvider))
            {
                target = anchor as IDataContextProvider ?? throw new InvalidOperationException("Cannot find a DataContext to bind to.");
            }

            if (!targetIsDataContext)
            {
                var result = new ExpressionObserver(
                    () => target.GetValue(StyledElement.DataContextProperty),
                    node,
                    new UpdateSignal(target, StyledElement.DataContextProperty),
                    null);

                return(result);
            }
            else
            {
                return(new ExpressionObserver(
                           GetParentDataContext(target),
                           node,
                           null));
            }
        }
예제 #6
0
        /// <summary>
        /// Gets the value for the RegionName attached property.
        /// </summary>
        /// <param name="element">The object to adapt. This is typically a container (i.e a control).</param>
        /// <returns>The name of the region that should be created when
        /// the RegionManager is also set in this element.</returns>
        public string GetRegionName(IAvaloniaObject element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            return(element.GetValue(RegionManager.RegionNameProperty) as string);
        }
예제 #7
0
        /// <summary>
        /// Gets the value of the RegionName attached property.
        /// </summary>
        /// <param name="element">The target element.</param>
        /// <returns>The <see cref="IRegionManager"/> attached to the <paramref name="element"/> element.</returns>
        public IRegionManager GetRegionManager(IAvaloniaObject element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            return(element.GetValue(RegionManager.RegionManagerProperty) as IRegionManager);
        }
예제 #8
0
        /// <summary>
        /// Gets the value of the <see cref="RegionNameProperty"/> attached property.
        /// </summary>
        /// <param name="target">The target element.</param>
        /// <returns>The <see cref="IRegionManager"/> attached to the <paramref name="target"/> element.</returns>
        public static IRegionManager GetRegionManager(IAvaloniaObject target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            return((IRegionManager)target.GetValue(RegionManagerProperty));
        }
예제 #9
0
 /// <summary>
 /// Gets the default value for a property.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>The default value.</returns>
 private object GetDefaultValue(AvaloniaProperty property)
 {
     if (property.Inherits && _inheritanceParent != null)
     {
         return(_inheritanceParent.GetValue(property));
     }
     else
     {
         return(((IStyledPropertyAccessor)property).GetDefaultValue(GetType()));
     }
 }
예제 #10
0
        protected ExpressionObserver CreateTemplatedParentObserver(
            IAvaloniaObject target,
            ExpressionNode node)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            var result = new ExpressionObserver(
                () => target.GetValue(StyledElement.TemplatedParentProperty),
                node,
                new UpdateSignal(target, StyledElement.TemplatedParentProperty),
                null);

            return(result);
        }
예제 #11
0
        protected ExpressionObserver CreateTemplatedParentObserver(
            IAvaloniaObject target,
            ExpressionNode node)
        {
            _ = target ?? throw new ArgumentNullException(nameof(target));

            var result = new ExpressionObserver(
                () => target.GetValue(StyledElement.TemplatedParentProperty),
                node,
                new UpdateSignal(target, StyledElement.TemplatedParentProperty),
                null);

            return(result);
        }
예제 #12
0
        private ExpressionObserver CreateTemplatedParentObserver(
            IAvaloniaObject target,
            string path,
            bool enableDataValidation)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            var result = new ExpressionObserver(
                () => target.GetValue(StyledElement.TemplatedParentProperty),
                path,
                new UpdateSignal(target, StyledElement.TemplatedParentProperty),
                enableDataValidation);

            return(result);
        }
예제 #13
0
파일: Binding.cs 프로젝트: sqdavid/Avalonia
        private ExpressionObserver CreateTemplatedParentObserver(
            IAvaloniaObject target,
            string path)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            var update = target.GetObservable(Control.TemplatedParentProperty)
                         .Skip(1)
                         .Select(_ => Unit.Default);

            var result = new ExpressionObserver(
                () => target.GetValue(Control.TemplatedParentProperty),
                path,
                update);

            return(result);
        }
예제 #14
0
        /// <summary>
        /// Called for each inherited property when the <see cref="InheritanceParent"/> changes.
        /// </summary>
        /// <typeparam name="T">The type of the property value.</typeparam>
        /// <param name="property">The property.</param>
        /// <param name="oldParent">The old inheritance parent.</param>
        internal void InheritanceParentChanged <T>(
            StyledPropertyBase <T> property,
            IAvaloniaObject oldParent)
        {
            var oldValue = oldParent switch
            {
                AvaloniaObject o => o.GetValueOrInheritedOrDefault(property),
                null => property.GetDefaultValue(GetType()),
                _ => oldParent.GetValue(property)
            };

            var newValue = GetInheritedOrDefault(property);

            if (!EqualityComparer <T> .Default.Equals(oldValue, newValue))
            {
                RaisePropertyChanged(property, oldValue, newValue);
            }
        }
예제 #15
0
파일: Binding.cs 프로젝트: sqdavid/Avalonia
        private ExpressionObserver CreateDataContexObserver(
            IAvaloniaObject target,
            string path,
            bool targetIsDataContext,
            object anchor)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            if (!(target is IControl))
            {
                target = anchor as IControl;

                if (target == null)
                {
                    throw new InvalidOperationException("Cannot find a DataContext to bind to.");
                }
            }

            if (!targetIsDataContext)
            {
                var update = target.GetObservable(Control.DataContextProperty)
                             .Skip(1)
                             .Select(_ => Unit.Default);
                var result = new ExpressionObserver(
                    () => target.GetValue(Control.DataContextProperty),
                    path,
                    update,
                    EnableValidation);

                return(result);
            }
            else
            {
                return(new ExpressionObserver(
                           target.GetObservable(Visual.VisualParentProperty)
                           .OfType <IAvaloniaObject>()
                           .Select(x => x.GetObservable(Control.DataContextProperty))
                           .Switch(),
                           path,
                           EnableValidation));
            }
        }
예제 #16
0
        private ExpressionObserver CreateDataContextObserver(
            IAvaloniaObject target,
            string path,
            bool targetIsDataContext,
            object anchor,
            bool enableDataValidation)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            if (!(target is IStyledElement))
            {
                target = anchor as IStyledElement;

                if (target == null)
                {
                    throw new InvalidOperationException("Cannot find a DataContext to bind to.");
                }
            }

            if (!targetIsDataContext)
            {
                var update = target.GetObservable(StyledElement.DataContextProperty)
                             .Skip(1)
                             .Select(_ => Unit.Default);
                var result = new ExpressionObserver(
                    () => target.GetValue(StyledElement.DataContextProperty),
                    path,
                    update,
                    enableDataValidation);

                return(result);
            }
            else
            {
                return(new ExpressionObserver(
                           GetParentDataContext(target),
                           path,
                           enableDataValidation));
            }
        }
예제 #17
0
        private ExpressionObserver CreateDataContextObserver(
            IAvaloniaObject target,
            string path,
            bool targetIsDataContext,
            object anchor,
            bool enableDataValidation)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            if (!(target is IStyledElement))
            {
                target = anchor as IStyledElement;

                if (target == null)
                {
                    throw new InvalidOperationException("Cannot find a DataContext to bind to.");
                }
            }

            if (!targetIsDataContext)
            {
                var result = ExpressionObserverBuilder.Build(
                    () => target.GetValue(StyledElement.DataContextProperty),
                    path,
                    new UpdateSignal(target, StyledElement.DataContextProperty),
                    enableDataValidation,
                    typeResolver: TypeResolver);

                return(result);
            }
            else
            {
                return(ExpressionObserverBuilder.Build(
                           GetParentDataContext(target),
                           path,
                           enableDataValidation,
                           typeResolver: TypeResolver));
            }
        }
예제 #18
0
파일: Binding.cs 프로젝트: pcbing/Avalonia
        private ExpressionObserver CreateDataContextObserver(
            IAvaloniaObject target,
            ExpressionNode node,
            bool targetIsDataContext,
            object anchor)
        {
            Contract.Requires <ArgumentNullException>(target != null);

            if (!(target is IStyledElement))
            {
                target = anchor as IStyledElement;

                if (target == null)
                {
                    throw new InvalidOperationException("Cannot find a DataContext to bind to.");
                }
            }

            if (!targetIsDataContext)
            {
                var result = new ExpressionObserver(
                    () => target.GetValue(StyledElement.DataContextProperty),
                    node,
                    new UpdateSignal(target, StyledElement.DataContextProperty),
                    null);

                return(result);
            }
            else
            {
                return(new ExpressionObserver(
                           GetParentDataContext(target),
                           node,
                           null));
            }
        }
예제 #19
0
        private ExpressionObserver CreateDataContexObserver(
            IAvaloniaObject target,
            string path,
            bool targetIsDataContext,
            object anchor)
        {
            Contract.Requires<ArgumentNullException>(target != null);

            if (!(target is IControl))
            {
                target = anchor as IControl;

                if (target == null)
                {
                    throw new InvalidOperationException("Cannot find a DataContext to bind to.");
                }
            }

            if (!targetIsDataContext)
            {
                var update = target.GetObservable(Control.DataContextProperty)
                    .Skip(1)
                    .Select(_ => Unit.Default);
                var result = new ExpressionObserver(
                    () => target.GetValue(Control.DataContextProperty),
                    path,
                    update,
                    EnableValidation);

                return result;
            }
            else
            {
                return new ExpressionObserver(
                    target.GetObservable(Visual.VisualParentProperty)
                          .OfType<IAvaloniaObject>()
                          .Select(x => x.GetObservable(Control.DataContextProperty))
                          .Switch(),
                    path,
                    EnableValidation);
            }
        }
        /*static BorderPresence()
         * {
         *  Layoutable.AffectsMeasure<Control>(BorderPresenceProperty);
         * }*/

        public static BorderPresence GetBorderPresence(IAvaloniaObject obj)
        {
            return(obj.GetValue(BorderPresenceProperty));
        }
예제 #21
0
 /// <inheritdoc/>
 internal override object?RouteGetValue(IAvaloniaObject o)
 {
     return(o.GetValue <TValue>(this));
 }
예제 #22
0
 public static bool GetAutoWireViewModel(IAvaloniaObject obj)
 {
     return((bool)obj.GetValue(AutoWireViewModelProperty));
 }
예제 #23
0
 public static string GetSyntaxExtension(IAvaloniaObject obj)
 {
     return(obj.GetValue(SyntaxExtensionProperty));
 }
 public static ObservableCollection <DatabaseColumnHeaderViewModel> GetColumnsWithHeader(IAvaloniaObject obj)
 {
     return(obj.GetValue(ColumnsWithHeaderProperty));
 }
예제 #25
0
 public static bool GetIsDropTarget(IAvaloniaObject obj)
 {
     return((bool)obj.GetValue(IsDropTargetProperty));
 }
예제 #26
0
 public static bool GetIsDragSource(IAvaloniaObject obj)
 {
     return((bool)obj.GetValue(IsDragSourceProperty));
 }
예제 #27
0
        private ExpressionObserver CreateTemplatedParentObserver(
            IAvaloniaObject target,
            string path)
        {
            Contract.Requires<ArgumentNullException>(target != null);

            var update = target.GetObservable(Control.TemplatedParentProperty)
                .Skip(1)
                .Select(_ => Unit.Default);

            var result = new ExpressionObserver(
                () => target.GetValue(Control.TemplatedParentProperty),
                path,
                update);

            return result;
        }
예제 #28
0
 public static object GetIcon(IAvaloniaObject obj)
 {
     return(obj.GetValue(IconProperty));
 }
예제 #29
0
 public static double GetIconGap(IAvaloniaObject obj)
 {
     return(obj.GetValue(IconGapProperty));
 }
예제 #30
0
 public static CornerCurves GetCornerCurves(IAvaloniaObject obj)
 {
     return(obj.GetValue(CornerCurvesProperty));
 }
예제 #31
0
 public static IDropTarget?GetDropHandler(IAvaloniaObject obj)
 {
     return((IDropTarget?)obj.GetValue(DropHandlerProperty));
 }
예제 #32
0
 internal override object?RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority)
 {
     return(o.GetValue <TValue>(this));
 }