Exemplo n.º 1
0
        /// <inheritdoc/>
        internal override IDisposable?RouteSetValue(
            AvaloniaObject o,
            object?value,
            BindingPriority priority)
        {
            var v = TryConvert(value);

            if (v.HasValue)
            {
                o.SetValue <TValue>(this, (TValue)v.Value !);
            }
            else if (v.Type == BindingValueType.UnsetValue)
            {
                o.ClearValue(this);
            }
            else if (v.HasError)
            {
                throw v.Error !;
            }

            return(null);
        }
Exemplo n.º 2
0
 internal abstract void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent);
Exemplo n.º 3
0
 public ValueStore(AvaloniaObject owner)
 {
     _sink   = _owner = owner;
     _values = new AvaloniaPropertyValueStore <IValue>();
 }
Exemplo n.º 4
0
 /// <inheritdoc/>
 internal override void RouteInheritanceParentChanged(
     AvaloniaObject o,
     IAvaloniaObject?oldParent)
 {
     o.InheritanceParentChanged(this, oldParent);
 }
        /// <summary>
        /// Gets all <see cref="AvaloniaProperty"/>s registered on a object.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <returns>A collection of <see cref="AvaloniaProperty"/> definitions.</returns>
        public IEnumerable <AvaloniaProperty> GetRegistered(AvaloniaObject o)
        {
            Contract.Requires <ArgumentNullException>(o != null);

            return(GetRegistered(o.GetType()));
        }
 /// <summary>
 /// Finds a registered property on an object by name.
 /// </summary>
 /// <param name="o">The object.</param>
 /// <param name="name">
 /// The property name. If an attached property it should be in the form
 /// "OwnerType.PropertyName".
 /// </param>
 /// <returns>
 /// The registered property or null if no matching property found.
 /// </returns>
 public AvaloniaProperty FindRegistered(AvaloniaObject o, string name)
 {
     return(FindRegistered(o.GetType(), name));
 }
Exemplo n.º 7
0
 internal override void RouteInheritanceParentChanged(AvaloniaObject o, IAvaloniaObject oldParent)
 {
     throw new NotSupportedException("Direct properties do not support inheritance.");
 }
Exemplo n.º 8
0
 /// <inheritdoc/>
 internal override object?RouteGetValue(AvaloniaObject o)
 {
     return(o.GetValue <TValue>(this));
 }
Exemplo n.º 9
0
 internal override object?RouteGetBaseValue(AvaloniaObject o, BindingPriority maxPriority)
 {
     return(o.GetValue <TValue>(this));
 }
Exemplo n.º 10
0
 /// <inheritdoc/>
 internal override void RouteClearValue(AvaloniaObject o)
 {
     o.ClearValue <TValue>(this);
 }
Exemplo n.º 11
0
        internal void NotifyInitialized(AvaloniaObject o)
        {
            Contract.Requires <ArgumentNullException>(o != null);

            var type = o.GetType();

            void Notify(AvaloniaProperty property, object value)
            {
                var e = new AvaloniaPropertyChangedEventArgs(
                    o,
                    property,
                    AvaloniaProperty.UnsetValue,
                    value,
                    BindingPriority.Unset);

                property.NotifyInitialized(e);
            }

            if (!_initializedCache.TryGetValue(type, out var initializationData))
            {
                var visited = new HashSet <AvaloniaProperty>();

                initializationData = new List <PropertyInitializationData>();

                foreach (AvaloniaProperty property in GetRegistered(type))
                {
                    if (property.IsDirect)
                    {
                        initializationData.Add(new PropertyInitializationData(property, (IDirectPropertyAccessor)property));
                    }
                    else
                    {
                        initializationData.Add(new PropertyInitializationData(property, (IStyledPropertyAccessor)property, type));
                    }

                    visited.Add(property);
                }

                foreach (AvaloniaProperty property in GetRegisteredAttached(type))
                {
                    if (!visited.Contains(property))
                    {
                        initializationData.Add(new PropertyInitializationData(property, (IStyledPropertyAccessor)property, type));

                        visited.Add(property);
                    }
                }

                _initializedCache.Add(type, initializationData);
            }

            foreach (PropertyInitializationData data in initializationData)
            {
                if (!data.Property.HasNotifyInitializedObservers)
                {
                    continue;
                }

                object value = data.IsDirect ? data.DirectAccessor.GetValue(o) : data.Value;

                Notify(data.Property, value);
            }
        }
Exemplo n.º 12
0
 public ValueStore(AvaloniaObject owner)
 {
     _owner = owner;
 }
        /// <inheritdoc/>
        internal override object?RouteGetBaseValue(AvaloniaObject o, BindingPriority maxPriority)
        {
            var value = o.GetBaseValue <TValue>(this, maxPriority);

            return(value.HasValue ? value.Value : AvaloniaProperty.UnsetValue);
        }
Exemplo n.º 14
0
 public ValueStore(AvaloniaObject owner)
 {
     _owner = owner;
     _propertyValues = new AvaloniaPropertyValueStore<object>();
     _deferredSetters = new AvaloniaPropertyValueStore<object>();
 }