Пример #1
0
        /// <summary>
        /// Binds a property on an <see cref="IPerspexObject"/> to an <see cref="IBinding"/>.
        /// </summary>
        /// <param name="o">The object.</param>
        /// <param name="property">The property to bind.</param>
        /// <param name="binding">The binding.</param>
        /// <returns>An <see cref="IDisposable"/> which can be used to cancel the binding.</returns>
        public static IDisposable Bind(
            this IPerspexObject o,
            PerspexProperty property,
            IBinding binding)
        {
            Contract.Requires <ArgumentNullException>(o != null);
            Contract.Requires <ArgumentNullException>(property != null);
            Contract.Requires <ArgumentNullException>(binding != null);

            var mode = binding.Mode;

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

            return(o.Bind(
                       property,
                       binding.CreateSubject(o, property),
                       mode,
                       binding.Priority));
        }
Пример #2
0
 /// <summary>
 /// Converts an unset value to the default value for a direct property.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="property">The property.</param>
 /// <returns>The value.</returns>
 private object DirectUnsetToDefault(object value, PerspexProperty property)
 {
     return(value == PerspexProperty.UnsetValue ?
            ((IDirectPropertyMetadata)property.GetMetadata(GetType())).UnsetValue :
            value);
 }