/// <inheritdoc/>
        public InstancedBinding Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor = null)
        {
            if (Name == "Red")
            {
            }

            var host = (target as IControl) ?? (anchor as IControl);
            var style = anchor as IStyle;
            var resource = AvaloniaProperty.UnsetValue;

            if (host != null)
            {
                resource = host.FindStyleResource(Name);
            }
            else if (style != null)
            {
                resource = style.FindResource(Name);
            }

            if (resource != AvaloniaProperty.UnsetValue)
            {
                return new InstancedBinding(resource, Priority);
            }
            else
            {
                return null;
            }
        }
        public PropertyEqualsSelector(Selector previous, AvaloniaProperty property, object value)
        {
            Contract.Requires<ArgumentNullException>(property != null);

            _previous = previous;
            _property = property;
            _value = value;
        }
            public Accessor(WeakReference<AvaloniaObject> reference, AvaloniaProperty property)
            {
                Contract.Requires<ArgumentNullException>(reference != null);
                Contract.Requires<ArgumentNullException>(property != null);

                _reference = reference;
                _property = property;
            }
 /// <summary>
 /// Merges the metadata with the base metadata.
 /// </summary>
 /// <param name="baseMetadata">The base metadata to merge.</param>
 /// <param name="property">The property to which the metadata is being applied.</param>
 public virtual void Merge(
     PropertyMetadata baseMetadata, 
     AvaloniaProperty property)
 {
     if (_defaultBindingMode == BindingMode.Default)
     {
         _defaultBindingMode = baseMetadata.DefaultBindingMode;
     }
 }
 public IndexerBinding(
     IAvaloniaObject source,
     AvaloniaProperty property,
     BindingMode mode)
 {
     Source = source;
     Property = property;
     Mode = mode;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AvaloniaPropertyValue"/> class.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="value">The current property value.</param>
 /// <param name="priority">The priority of the current value.</param>
 /// <param name="diagnostic">A diagnostic string.</param>
 public AvaloniaPropertyValue(
     AvaloniaProperty property,
     object value,
     BindingPriority priority,
     string diagnostic)
 {
     Property = property;
     Value = value;
     Priority = priority;
     Diagnostic = diagnostic;
 }
            public Accessor(
                WeakReference<AvaloniaObject> reference, 
                AvaloniaProperty property, 
                Action<object> changed)
            {
                Contract.Requires<ArgumentNullException>(reference != null);
                Contract.Requires<ArgumentNullException>(property != null);

                _reference = reference;
                _property = property;
                _subscription = Instance.GetWeakObservable(property).Skip(1).Subscribe(changed);
            }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriorityValue"/> class.
 /// </summary>
 /// <param name="owner">The owner of the object.</param>
 /// <param name="property">The property that the value represents.</param>
 /// <param name="valueType">The value type.</param>
 /// <param name="validate">An optional validation function.</param>
 public PriorityValue(
     IPriorityValueOwner owner,
     AvaloniaProperty property, 
     Type valueType,
     Func<object, object> validate = null)
 {
     _owner = owner;
     Property = property;
     _valueType = valueType;
     _value = AvaloniaProperty.UnsetValue;
     ValuePriority = int.MaxValue;
     _validate = validate;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AvaloniaPropertyChangedEventArgs"/> class.
 /// </summary>
 /// <param name="sender">The object that the property changed on.</param>
 /// <param name="property">The property that changed.</param>
 /// <param name="oldValue">The old value of the property.</param>
 /// <param name="newValue">The new value of the property.</param>
 /// <param name="priority">The priority of the binding that produced the value.</param>
 public AvaloniaPropertyChangedEventArgs(
     AvaloniaObject sender,
     AvaloniaProperty property,
     object oldValue,
     object newValue,
     BindingPriority priority)
 {
     Sender = sender;
     Property = property;
     OldValue = oldValue;
     NewValue = newValue;
     Priority = priority;
 }
 private static void SetBinding(
     object instance,
     MutableMember member, 
     AvaloniaProperty property, 
     IValueContext context,
     IBinding binding)
 {
     if (!(AssignBinding(instance, member, binding) || 
           ApplyBinding(instance, property, context, binding)))
     {
         throw new InvalidOperationException(
             $"Cannot assign to '{member.Name}' on '{instance.GetType()}");
     }
 }
Beispiel #11
0
        public InstancedBinding Initiate(IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null)
        {
            var mode = Mode == BindingMode.Default ?
                targetProperty.GetMetadata(target.GetType()).DefaultBindingMode :
                Mode;

            if (mode == BindingMode.TwoWay)
            {
                return new InstancedBinding(Source.GetSubject(Property), mode);
            }
            else
            {
                return new InstancedBinding(Source.GetObservable(Property), mode);
            }
        }
        /// <summary>
        /// Applies an <see cref="InstancedBinding"/> a property on an <see cref="IAvaloniaObject"/>.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <param name="property">The property to bind.</param>
        /// <param name="binding">The instanced binding.</param>
        /// <param name="anchor">
        /// An optional anchor from which to locate required context. When binding to objects that
        /// are not in the logical tree, certain types of binding need an anchor into the tree in 
        /// order to locate named controls or resources. The <paramref name="anchor"/> parameter 
        /// can be used to provice this context.
        /// </param>
        /// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
        public static IDisposable Apply(
            IAvaloniaObject target,
            AvaloniaProperty property,
            InstancedBinding binding,
            object anchor)
        {
            Contract.Requires<ArgumentNullException>(target != null);
            Contract.Requires<ArgumentNullException>(property != null);
            Contract.Requires<ArgumentNullException>(binding != null);

            var mode = binding.Mode;

            if (mode == BindingMode.Default)
            {
                mode = property.GetMetadata(target.GetType()).DefaultBindingMode;
            }

            switch (mode)
            {
                case BindingMode.Default:
                case BindingMode.OneWay:
                    return target.Bind(property, binding.Observable ?? binding.Subject, binding.Priority);
                case BindingMode.TwoWay:
                    return new CompositeDisposable(
                        target.Bind(property, binding.Subject, binding.Priority),
                        target.GetObservable(property).Subscribe(binding.Subject));
                case BindingMode.OneTime:
                    var source = binding.Subject ?? binding.Observable;

                    if (source != null)
                    {
                        return source
                            .Where(x => BindingNotification.ExtractValue(x) != AvaloniaProperty.UnsetValue)
                            .Take(1)
                            .Subscribe(x => target.SetValue(property, x, binding.Priority));
                    }
                    else
                    {
                        target.SetValue(property, binding.Value, binding.Priority);
                        return Disposable.Empty;
                    }
                case BindingMode.OneWayToSource:
                    return target.GetObservable(property).Subscribe(binding.Subject);
                default:
                    throw new ArgumentException("Invalid binding mode.");
            }
        }
Beispiel #13
0
        /// <inheritdoc/>
        public InstancedBinding Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor = null)
        {
            if (Converter == null)
            {
                throw new NotSupportedException("MultiBinding without Converter not currently supported.");
            }

            var targetType = targetProperty?.PropertyType ?? typeof(object);
            var result = new BehaviorSubject<object>(AvaloniaProperty.UnsetValue);
            var children = Bindings.Select(x => x.Initiate(target, null));
            var input = children.Select(x => x.Subject).CombineLatest().Select(x => ConvertValue(x, targetType));
            input.Subscribe(result);
            return new InstancedBinding(result, Mode, Priority);
        }
Beispiel #14
0
        public PropertyDetails(AvaloniaObject o, AvaloniaProperty property)
        {
            Name = property.IsAttached ?
                $"[{property.OwnerType.Name}.{property.Name}]" :
                property.Name;
            IsAttached = property.IsAttached;

            // TODO: Unsubscribe when view model is deactivated.
            o.GetObservable(property).Subscribe(x =>
            {
                var diagnostic = o.GetDiagnostic(property);
                Value = diagnostic.Value ?? "(null)";
                Priority = (diagnostic.Priority != BindingPriority.Unset) ?
                    diagnostic.Priority.ToString() :
                    diagnostic.Property.Inherits ? "Inherited" : "Unset";
                Diagnostic = diagnostic.Diagnostic;
            });
        }
Beispiel #15
0
        /// <summary>
        /// Adds a delayed binding to a control.
        /// </summary>
        /// <param name="target">The control.</param>
        /// <param name="property">The property on the control to bind to.</param>
        /// <param name="binding">The binding.</param>
        public static void Add(IControl target, AvaloniaProperty property, IBinding binding)
        {
            if (target.IsInitialized)
            {
                target.Bind(property, binding);
            }
            else
            {
                List<Entry> bindings;

                if (!_entries.TryGetValue(target, out bindings))
                {
                    bindings = new List<Entry>();
                    _entries.Add(target, bindings);

                    // TODO: Make this a weak event listener.
                    target.Initialized += ApplyBindings;
                }

                bindings.Add(new Entry(binding, property));
            }
        }
Beispiel #16
0
        private static void LogError(object source, AvaloniaProperty property, Exception e)
        {
            var level = LogEventLevel.Warning;

            if (e is BindingChainException b &&
                !string.IsNullOrEmpty(b.Expression) &&
                string.IsNullOrEmpty(b.ExpressionErrorPoint))
            {
                // The error occurred at the root of the binding chain: it's possible that the
                // DataContext isn't set up yet, so log at Information level instead of Warning
                // to prevent spewing hundreds of errors.
                level = LogEventLevel.Information;
            }

            Logger.Log(
                level,
                LogArea.Binding,
                source,
                "Error in binding to {Target}.{Property}: {Message}",
                source,
                property,
                e.Message);
        }
        /// <summary>
        /// Gets a diagnostic for a <see cref="AvaloniaProperty"/> on a <see cref="AvaloniaObject"/>.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A <see cref="AvaloniaPropertyValue"/> that can be used to diagnose the state of the
        /// property on the object.
        /// </returns>
        public static AvaloniaPropertyValue GetDiagnostic(this AvaloniaObject o, AvaloniaProperty property)
        {
            var set = o.GetSetValues();

            PriorityValue value;

            if (set.TryGetValue(property, out value))
            {
                return new AvaloniaPropertyValue(
                    property,
                    o.GetValue(property),
                    (BindingPriority)value.ValuePriority,
                    value.GetDiagnostic());
            }
            else
            {
                return new AvaloniaPropertyValue(
                    property,
                    o.GetValue(property),
                    BindingPriority.Unset,
                    "Unset");
            }
        }
        /// <summary>
        /// Gets a diagnostic for a <see cref="AvaloniaProperty"/> on a <see cref="AvaloniaObject"/>.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <param name="property">The property.</param>
        /// <returns>
        /// A <see cref="AvaloniaPropertyValue"/> that can be used to diagnose the state of the
        /// property on the object.
        /// </returns>
        public static AvaloniaPropertyValue GetDiagnostic(this AvaloniaObject o, AvaloniaProperty property)
        {
            var set = o.GetSetValues();

            PriorityValue value;

            if (set.TryGetValue(property, out value))
            {
                return(new AvaloniaPropertyValue(
                           property,
                           o.GetValue(property),
                           (BindingPriority)value.ValuePriority,
                           value.GetDiagnostic()));
            }
            else
            {
                return(new AvaloniaPropertyValue(
                           property,
                           o.GetValue(property),
                           BindingPriority.Unset,
                           "Unset"));
            }
        }
Beispiel #19
0
        protected override void OnPropertyChanged <T>(
            AvaloniaProperty <T> property,
            Optional <T> oldValue,
            BindingValue <T> newValue,
            BindingPriority priority)
        {
            base.OnPropertyChanged(property, oldValue, newValue, priority);

            if (property == OrientationProperty)
            {
                UpdatePseudoClasses(newValue.GetValueOrDefault <Orientation>());
            }
            else
            {
                if (property == MinimumProperty ||
                    property == MaximumProperty ||
                    property == ViewportSizeProperty ||
                    property == VisibilityProperty)
                {
                    UpdateIsVisible();
                }
            }
        }
        public BindingSetterViewModel(AvaloniaProperty property, object?value) : base(property, value)
        {
            switch (value)
            {
            case Binding binding:
                Path             = binding.Path;
                Tint             = Brushes.CornflowerBlue;
                ValueTypeTooltip = "Reflection Binding";

                break;

            case CompiledBindingExtension binding:
                Path             = binding.Path.ToString();
                Tint             = Brushes.DarkGreen;
                ValueTypeTooltip = "Compiled Binding";

                break;

            case TemplateBinding binding:
                if (binding.Property is AvaloniaProperty templateProperty)
                {
                    Path = $"{templateProperty.OwnerType.Name}.{templateProperty.Name}";
                }
                else
                {
                    Path = "Unassigned";
                }

                Tint             = Brushes.OrangeRed;
                ValueTypeTooltip = "Template Binding";

                break;

            default:
                throw new ArgumentException("Invalid binding type", nameof(value));
            }
        }
Beispiel #21
0
        /// <inheritdoc/>
        public InstancedBinding Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor             = null,
            bool enableDataValidation = false)
        {
            var targetType = targetProperty?.PropertyType ?? typeof(object);
            var converter  = Converter;

            // We only respect `StringFormat` if the type of the property we're assigning to will
            // accept a string. Note that this is slightly different to WPF in that WPF only applies
            // `StringFormat` for target type `string` (not `object`).
            if (!string.IsNullOrWhiteSpace(StringFormat) &&
                (targetType == typeof(string) || targetType == typeof(object)))
            {
                converter = new StringFormatMultiValueConverter(StringFormat, converter);
            }

            var children = Bindings.Select(x => x.Initiate(target, null));
            var input    = children.Select(x => x.Observable).CombineLatest().Select(x => ConvertValue(x, targetType, converter));
            var mode     = Mode == BindingMode.Default ?
                           targetProperty?.GetMetadata(target.GetType()).DefaultBindingMode : Mode;

            switch (mode)
            {
            case BindingMode.OneTime:
                return(InstancedBinding.OneTime(input, Priority));

            case BindingMode.OneWay:
                return(InstancedBinding.OneWay(input, Priority));

            default:
                throw new NotSupportedException(
                          "MultiBinding currently only supports OneTime and OneWay BindingMode.");
            }
        }
Beispiel #22
0
        private static void SuspendHandler(this AvaloniaObject obj, AvaloniaProperty AvaloniaProperty, bool suspend)
        {
            if (_suspendedHandlers.ContainsKey(obj))
            {
                Dictionary <AvaloniaProperty, bool> suspensions = _suspendedHandlers[obj];

                if (suspend)
                {
                    Debug.Assert(!suspensions.ContainsKey(AvaloniaProperty));
                    suspensions[AvaloniaProperty] = true; // true = dummy value
                }
                else
                {
                    Debug.Assert(suspensions.ContainsKey(AvaloniaProperty));
                    suspensions.Remove(AvaloniaProperty);
                }
            }
            else
            {
                Debug.Assert(suspend);
                _suspendedHandlers[obj] = new Dictionary <AvaloniaProperty, bool>();
                _suspendedHandlers[obj][AvaloniaProperty] = true;
            }
        }
Beispiel #23
0
        public static StyledProperty <TValue> Register <TOwner, TValue>(string name,
                                                                        TValue defaultValue = default, PropertyOptions options = PropertyOptions.None,
                                                                        Action <TOwner, CommonPropertyChangedArgs <TValue> >?onChanged = null)
            where TOwner : AvaloniaObject
        {
            var property = AvaloniaProperty.Register <TOwner, TValue>(name, defaultValue,
                                                                      options.Has(PropertyOptions.Inherits),
                                                                      options.Has(PropertyOptions.BindsTwoWay)
                    ? Avalonia.Data.BindingMode.TwoWay
                    : Avalonia.Data.BindingMode.OneWay);

            if (options.Has(PropertyOptions.AffectsRender))
            {
                AffectsRender(new[] { property });
            }

            if (options.Has(PropertyOptions.AffectsArrange))
            {
                AffectsArrange(new[] { property });
            }

            if (options.Has(PropertyOptions.AffectsMeasure))
            {
                AffectsMeasure(new[] { property });
            }

            var onChangedLocal = onChanged;

            if (onChangedLocal != null)
            {
                property.Changed.AddClassHandler <TOwner>(
                    (o, e) => onChangedLocal(o, new CommonPropertyChangedArgs <TValue>((TValue)e.OldValue, (TValue)e.NewValue)));
            }

            return(property);
        }
Beispiel #24
0
        /// <summary>
        /// Applies a binding subject to a property on an instance.
        /// </summary>
        /// <param name="target">The target instance.</param>
        /// <param name="property">The target property.</param>
        /// <param name="subject">The binding subject.</param>
        internal void Bind(IAvaloniaObject target, AvaloniaProperty property, ISubject<object> subject)
        {
            var mode = Mode == BindingMode.Default ?
                property.GetMetadata(target.GetType()).DefaultBindingMode : Mode;

            switch (mode)
            {
                case BindingMode.Default:
                case BindingMode.OneWay:
                    target.Bind(property, subject, Priority);
                    break;
                case BindingMode.TwoWay:
                    throw new NotSupportedException("TwoWay MultiBinding not currently supported.");
                case BindingMode.OneTime:
                    target.GetObservable(Control.DataContextProperty).Subscribe(dataContext =>
                    {
                        subject.Take(1).Subscribe(x => target.SetValue(property, x, Priority));
                    });                    
                    break;
                case BindingMode.OneWayToSource:
                    target.GetObservable(property).Subscribe(subject);
                    break;
            }
        }
Beispiel #25
0
        InstancedBinding?IBinding.Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor,
            bool enableDataValidation)
        {
            if (ResourceKey is null)
            {
                return(null);
            }

            var control = target as IStyledElement ?? _anchor as IStyledElement;

            if (control != null)
            {
                return(InstancedBinding.OneWay(control.GetResourceObservable(ResourceKey)));
            }
            else if (_resourceProvider is object)
            {
                return(InstancedBinding.OneWay(_resourceProvider.GetResourceObservable(ResourceKey)));
            }

            return(null);
        }
        public static void SetProperties(out AvaloniaProperty <RibbonControlSize> size, out AvaloniaProperty <RibbonControlSize> minSize, out AvaloniaProperty <RibbonControlSize> maxSize)
        {
            size    = SizeProperty;
            minSize = MinSizeProperty;
            maxSize = MaxSizeProperty;



            minSize.Changed.AddClassHandler <T>((sender, args) =>
            {
                if (((int)args.NewValue) > (int)((sender as IRibbonControl).Size))
                {
                    (sender as IRibbonControl).Size = (RibbonControlSize)(args.NewValue);
                }
            });

            maxSize.Changed.AddClassHandler <T>((sender, args) =>
            {
                if (((int)args.NewValue) < (int)((sender as IRibbonControl).Size))
                {
                    (sender as IRibbonControl).Size = (RibbonControlSize)(args.NewValue);
                }
            });
        }
        /// <summary>
        /// Registers a <see cref="AvaloniaProperty"/> on a type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="property">The property.</param>
        /// <remarks>
        /// You won't usually want to call this method directly, instead use the
        /// <see cref="AvaloniaProperty.Register"/> method.
        /// </remarks>
        public void Register(Type type, AvaloniaProperty property)
        {
            Contract.Requires<ArgumentNullException>(type != null);
            Contract.Requires<ArgumentNullException>(property != null);

            Dictionary<int, AvaloniaProperty> inner;

            if (!_registered.TryGetValue(type, out inner))
            {
                inner = new Dictionary<int, AvaloniaProperty>();
                _registered.Add(type, inner);
            }

            if (!inner.ContainsKey(property.Id))
            {
                inner.Add(property.Id, property);
            }

            if (property.IsAttached)
            {
                if (!_attached.TryGetValue(property.OwnerType, out inner))
                {
                    inner = new Dictionary<int, AvaloniaProperty>();
                    _attached.Add(property.OwnerType, inner);
                }

                if (!inner.ContainsKey(property.Id))
                {
                    inner.Add(property.Id, property);
                }
            }

            _registeredCache.Clear();
        }
 public Accessor(WeakReference <AvaloniaObject> reference, AvaloniaProperty property)
 {
     _reference = reference ?? throw new ArgumentNullException(nameof(reference));
     _property  = property ?? throw new ArgumentNullException(nameof(property));
 }
Beispiel #29
0
        /// <summary>
        /// Returns a selector which matches a control with the specified property value.
        /// </summary>
        /// <param name="previous">The previous selector.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The property value.</param>
        /// <returns>The selector.</returns>
        public static Selector PropertyEquals(this Selector previous, AvaloniaProperty property, object value)
        {
            Contract.Requires <ArgumentNullException>(property != null);

            return(new PropertyEqualsSelector(previous, property, value));
        }
Beispiel #30
0
        /// <inheritdoc/>
        public InstancedBinding Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor             = null,
            bool enableDataValidation = false)
        {
            Contract.Requires <ArgumentNullException>(target != null);
            anchor = anchor ?? DefaultAnchor?.Target;

            enableDataValidation = enableDataValidation && Priority == BindingPriority.LocalValue;

            ExpressionObserver observer;

            if (ElementName != null)
            {
                observer = CreateElementObserver(
                    (target as IStyledElement) ?? (anchor as IStyledElement),
                    ElementName,
                    Path,
                    enableDataValidation);
            }
            else if (Source != null)
            {
                observer = CreateSourceObserver(Source, Path, enableDataValidation);
            }
            else if (RelativeSource == null || RelativeSource.Mode == RelativeSourceMode.DataContext)
            {
                observer = CreateDataContextObserver(
                    target,
                    Path,
                    targetProperty == StyledElement.DataContextProperty,
                    anchor,
                    enableDataValidation);
            }
            else if (RelativeSource.Mode == RelativeSourceMode.Self)
            {
                observer = CreateSourceObserver(target, Path, enableDataValidation);
            }
            else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent)
            {
                observer = CreateTemplatedParentObserver(target, Path, enableDataValidation);
            }
            else if (RelativeSource.Mode == RelativeSourceMode.FindAncestor)
            {
                if (RelativeSource.Tree == TreeType.Visual && RelativeSource.AncestorType == null)
                {
                    throw new InvalidOperationException("AncestorType must be set for RelativeSourceMode.FindAncestor when searching the visual tree.");
                }

                observer = CreateFindAncestorObserver(
                    (target as IStyledElement) ?? (anchor as IStyledElement),
                    RelativeSource,
                    Path,
                    enableDataValidation);
            }
            else
            {
                throw new NotSupportedException();
            }

            var fallback = FallbackValue;

            // If we're binding to DataContext and our fallback is UnsetValue then override
            // the fallback value to null, as broken bindings to DataContext must reset the
            // DataContext in order to not propagate incorrect DataContexts to child controls.
            // See Avalonia.Markup.UnitTests.Data.DataContext_Binding_Should_Produce_Correct_Results.
            if (targetProperty == StyledElement.DataContextProperty && fallback == AvaloniaProperty.UnsetValue)
            {
                fallback = null;
            }

            var subject = new BindingExpression(
                observer,
                targetProperty?.PropertyType ?? typeof(object),
                fallback,
                Converter ?? DefaultValueConverter.Instance,
                ConverterParameter,
                Priority);

            return(new InstancedBinding(subject, Mode, Priority));
        }
Beispiel #31
0
 /// <summary>
 /// Adds a pseudo-class to be set when a property is true.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="className">The pseudo-class.</param>
 protected static void PseudoClass(AvaloniaProperty <bool> property, string className)
 {
     PseudoClass(property, x => x, className);
 }
Beispiel #32
0
 static GroupBox()
 {
     HeaderProperty = AvaloniaProperty.Register <GroupBox, string>(nameof(Header));
 }
 protected override void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
 {
     Notifications.Add(notification);
 }
 public InstancedBinding Initiate(IAvaloniaObject target, AvaloniaProperty targetProperty, object?anchor = null, bool enableDataValidation = false) =>
Beispiel #35
0
 public bool IsSet(AvaloniaProperty property)
 {
     throw new NotImplementedException();
 }
Beispiel #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Setter"/> class.
 /// </summary>
 /// <param name="property">The property to set.</param>
 /// <param name="value">The property value.</param>
 public Setter(AvaloniaProperty property, object value)
 {
     Property = property;
     Value = value;
 }
Beispiel #37
0
 public Entry(IBinding binding, AvaloniaProperty property)
 {
     Binding = binding;
     Property = property;
 }
 /// <summary>
 /// Finds <see cref="AvaloniaProperty"/> registered on an object.
 /// </summary>
 /// <param name="o">The object.</param>
 /// <param name="property">The property.</param>
 /// <returns>The registered property or null if not found.</returns>
 /// <remarks>
 /// Calling AddOwner on a AvaloniaProperty creates a new AvaloniaProperty that is a
 /// different object but is equal according to <see cref="object.Equals(object)"/>.
 /// </remarks>
 public AvaloniaProperty FindRegistered(object o, AvaloniaProperty property)
 {
     return FindRegistered(o.GetType(), property);
 }
        /// <summary>
        /// Finds a <see cref="AvaloniaProperty"/> registered on a type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="property">The property.</param>
        /// <returns>The registered property or null if not found.</returns>
        /// <remarks>
        /// Calling AddOwner on a AvaloniaProperty creates a new AvaloniaProperty that is a 
        /// different object but is equal according to <see cref="object.Equals(object)"/>.
        /// </remarks>
        public AvaloniaProperty FindRegistered(Type type, AvaloniaProperty property)
        {
            Type currentType = type;
            Dictionary<int, AvaloniaProperty> cache;
            AvaloniaProperty result;

            if (_registeredCache.TryGetValue(type, out cache))
            {
                if (cache.TryGetValue(property.Id, out result))
                {
                    return result;
                }
            }

            while (currentType != null)
            {
                Dictionary<int, AvaloniaProperty> inner;

                if (_registered.TryGetValue(currentType, out inner))
                {
                    if (inner.TryGetValue(property.Id, out result))
                    {
                        if (cache == null)
                        {
                            _registeredCache[type] = cache = new Dictionary<int, AvaloniaProperty>();
                        }

                        cache[property.Id] = result;

                        return result;
                    }
                }

                currentType = currentType.GetTypeInfo().BaseType;
            }

            return null;
        }
 protected override void DataValidationChanged(AvaloniaProperty property, IValidationStatus status)
 {
     if (property == ValidationTestProperty)
     {
         UpdateValidationState(status);
     }
 }
Beispiel #41
0
 public UpdateSignal(IAvaloniaObject target, AvaloniaProperty property)
 {
     _target   = target;
     _property = property;
 }
Beispiel #42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Setter"/> class.
 /// </summary>
 /// <param name="property">The property to set.</param>
 /// <param name="value">The property value.</param>
 public Setter(AvaloniaProperty property, object value)
 {
     Property = property;
     Value    = value;
 }
Beispiel #43
0
 /// <summary>
 /// Creates a new instance of <see cref="Scalable{T}"/> and initializes a new binding.
 /// </summary>
 /// <param name="avaloniaObject">The <see cref="AvaloniaObject"/> to apply the new binding to.</param>
 /// <param name="avaloniaProperty">The <see cref="AvaloniaProperty{TValue}"/> the new binding should be applied to.</param>
 /// <param name="defaultValue">The default value of the <paramref name="avaloniaProperty"/> at <c>1.0</c> scaling.</param>
 private protected Scalable(AvaloniaObject avaloniaObject, AvaloniaProperty <T> avaloniaProperty, T defaultValue)
 {
     Initialize(avaloniaObject, avaloniaProperty, defaultValue);
     isInitialized = true;
 }
Beispiel #44
0
        /// <inheritdoc/>
        public InstancedBinding Initiate(
            IAvaloniaObject target,
            AvaloniaProperty targetProperty,
            object anchor = null)
        {
            Contract.Requires<ArgumentNullException>(target != null);

            var pathInfo = ParsePath(Path);
            ValidateState(pathInfo);

            ExpressionObserver observer;

            if (pathInfo.ElementName != null || ElementName != null)
            {
                observer = CreateElementObserver(
                    (target as IControl) ?? (anchor as IControl),
                    pathInfo.ElementName ?? ElementName,
                    pathInfo.Path);
            }
            else if (Source != null)
            {
                observer = CreateSourceObserver(Source, pathInfo.Path);
            }
            else if (RelativeSource == null || RelativeSource.Mode == RelativeSourceMode.DataContext)
            {
                observer = CreateDataContexObserver(
                    target,
                    pathInfo.Path,
                    targetProperty == Control.DataContextProperty,
                    anchor);
            }
            else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent)
            {
                observer = CreateTemplatedParentObserver(target, pathInfo.Path);
            }
            else
            {
                throw new NotSupportedException();
            }

            var fallback = FallbackValue;

            // If we're binding to DataContext and our fallback is UnsetValue then override
            // the fallback value to null, as broken bindings to DataContext must reset the
            // DataContext in order to not propagate incorrect DataContexts to child controls.
            // See Avalonia.Markup.Xaml.UnitTests.Data.DataContext_Binding_Should_Produce_Correct_Results.
            if (targetProperty == Control.DataContextProperty && fallback == AvaloniaProperty.UnsetValue)
            {
                fallback = null;
            }

            var subject = new ExpressionSubject(
                observer,
                targetProperty?.PropertyType ?? typeof(object),
                fallback,
                Converter ?? DefaultValueConverter.Instance,
                ConverterParameter,
                Priority);

            return new InstancedBinding(subject, Mode, Priority);
        }
 public ConsolidateSetter(AvaloniaProperty property, object value)
     : this()
 {
     this.Property = property;
     this.Value    = value;
 }
 public TargetBindingEndpoint(AvaloniaObject obj, AvaloniaProperty property)
 {
     Object = obj;
     Property = property;
 }
 static RibbonButton()
 {
     TextProperty     = AvaloniaProperty.Register <RibbonButton, string>(nameof(Text));
     IconPathProperty = AvaloniaProperty.Register <RibbonButton, IBitmap>(nameof(IconPath));
 }
 protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification notification)
 {
     Notifications.Add(notification);
 }
Beispiel #49
0
 protected override void OnPropertyChanged <T>(AvaloniaProperty <T> property, Optional <T> oldValue, BindingValue <T> newValue, BindingPriority priority)
 {
     Order.Add($"Property {property.Name} Changed");
     base.OnPropertyChanged(property, oldValue, newValue, priority);
 }
Beispiel #50
0
 public T GetValue <T>(AvaloniaProperty <T> property)
 {
     throw new NotImplementedException();
 }
Beispiel #51
0
 public AvaloniaPropertyXamlMember(AvaloniaProperty property, XamlType type) :
     base(property.Name, type, false)
 {
     Property = property;
 }
Beispiel #52
0
 public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
 {
     throw new NotImplementedException();
 }
 static RibbonGroupBox()
 {
     CommandProperty = AvaloniaProperty.RegisterDirect <RibbonGroupBox, ICommand>(nameof(Command), button => button.Command, (button, command) => button.Command = command, enableDataValidation: true);
 }
Beispiel #54
0
 public void SetValue <T>(AvaloniaProperty <T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
 {
     throw new NotImplementedException();
 }
 public AvaloniaPropertyAccessorNode(AvaloniaProperty property, bool enableValidation)
 {
     _property         = property;
     _enableValidation = enableValidation;
 }
Beispiel #56
0
 public IDisposable Bind <T>(AvaloniaProperty <T> property, IObservable <T> source, BindingPriority priority = BindingPriority.LocalValue)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Checks whether a <see cref="AvaloniaProperty"/> is registered on a type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <returns>True if the property is registered, otherwise false.</returns>
 public bool IsRegistered(Type type, AvaloniaProperty property)
 {
     return FindRegistered(type, property) != null;
 }
        /// <summary>
        /// Finds a <see cref="AvaloniaProperty"/> registered on a type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="property">The property.</param>
        /// <returns>The registered property or null if not found.</returns>
        /// <remarks>
        /// Calling AddOwner on a AvaloniaProperty creates a new AvaloniaProperty that is a 
        /// different object but is equal according to <see cref="object.Equals(object)"/>.
        /// </remarks>
        public AvaloniaProperty FindRegistered(Type type, AvaloniaProperty property)
        {
            while (type != null)
            {
                Dictionary<int, AvaloniaProperty> inner;

                if (_registered.TryGetValue(type, out inner))
                {
                    AvaloniaProperty result;

                    if (inner.TryGetValue(property.Id, out result))
                    {
                        return result;
                    }
                }

                type = type.GetTypeInfo().BaseType;
            }

            return null;
        }
Beispiel #59
0
 public Entry(IBinding binding, AvaloniaProperty property)
 {
     Binding  = binding;
     Property = property;
 }
 /// <summary>
 /// Checks whether a <see cref="AvaloniaProperty"/> is registered on a object.
 /// </summary>
 /// <param name="o">The object.</param>
 /// <param name="property">The property.</param>
 /// <returns>True if the property is registered, otherwise false.</returns>
 public bool IsRegistered(object o, AvaloniaProperty property)
 {
     return IsRegistered(o.GetType(), property);
 }