Beispiel #1
0
        /// <summary>
        /// Registers a <see cref="PerspexProperty"/>.
        /// </summary>
        /// <typeparam name="TOwner">The type of the class that is registering the property.</typeparam>
        /// <typeparam name="TValue">The type of the property's value.</typeparam>
        /// <param name="name">The name of the property.</param>
        /// <param name="defaultValue">The default value of the property.</param>
        /// <param name="inherits">Whether the property inherits its value.</param>
        /// <param name="defaultBindingMode">The default binding mode for the property.</param>
        /// <param name="validate">A validation function.</param>
        /// <param name="notifying">
        /// A method that gets called before and after the property starts being notified on an
        /// object; the bool argument will be true before and false afterwards. This callback is
        /// intended to support IsDataContextChanging.
        /// </param>
        /// <returns>A <see cref="PerspexProperty{TValue}"/></returns>
        public static PerspexProperty <TValue> Register <TOwner, TValue>(
            string name,
            TValue defaultValue                    = default(TValue),
            bool inherits                          = false,
            BindingMode defaultBindingMode         = BindingMode.OneWay,
            Func <TOwner, TValue, TValue> validate = null,
            Action <PerspexObject, bool> notifying = null)
            where TOwner : PerspexObject
        {
            Contract.Requires <ArgumentNullException>(name != null);

            PerspexProperty <TValue> result = new PerspexProperty <TValue>(
                name,
                typeof(TOwner),
                defaultValue,
                inherits,
                defaultBindingMode,
                Cast(validate),
                notifying,
                false);

            PerspexObject.Register(typeof(TOwner), result);

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Registers the direct property on another type.
        /// </summary>
        /// <typeparam name="TOwner">The type of the additional owner.</typeparam>
        /// <returns>The property.</returns>
        public PerspexProperty <TValue> AddOwner <TOwner>(
            Func <TOwner, TValue> getter,
            Action <TOwner, TValue> setter = null)
            where TOwner : PerspexObject
        {
            var result = new PerspexProperty <TValue>(this, CastReturn(getter), CastParam1(setter));

            PerspexObject.Register(typeof(TOwner), result);
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Registers the property on another type.
        /// </summary>
        /// <typeparam name="TOwner">The type of the additional owner.</typeparam>
        /// <returns>The property.</returns>
        public PerspexProperty <TValue> AddOwner <TOwner>() where TOwner : PerspexObject
        {
            if (IsDirect)
            {
                throw new InvalidOperationException(
                          "You must provide a new getter and setter when calling AddOwner on a direct PerspexProperty.");
            }

            PerspexObject.Register(typeof(TOwner), this);
            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// Registers a direct <see cref="PerspexProperty"/>.
        /// </summary>
        /// <typeparam name="TOwner">The type of the class that is registering the property.</typeparam>
        /// <typeparam name="TValue">The type of the property's value.</typeparam>
        /// <param name="name">The name of the property.</param>
        /// <param name="getter">Gets the current value of the property.</param>
        /// <param name="setter">Sets the value of the property.</param>
        /// <returns>A <see cref="PerspexProperty{TValue}"/></returns>
        public static PerspexProperty <TValue> RegisterDirect <TOwner, TValue>(
            string name,
            Func <TOwner, TValue> getter,
            Action <TOwner, TValue> setter = null)
            where TOwner : PerspexObject
        {
            Contract.Requires <ArgumentNullException>(name != null);

            PerspexProperty <TValue> result = new PerspexProperty <TValue>(
                name,
                typeof(TOwner),
                Cast(getter),
                Cast(setter));

            PerspexObject.Register(typeof(TOwner), result);

            return(result);
        }
        /// <summary>
        /// Registers an attached <see cref="PerspexProperty"/>.
        /// </summary>
        /// <typeparam name="TOwner">The type of the class that is registering the property.</typeparam>
        /// <typeparam name="THost">The type of the class that the property is to be registered on.</typeparam>
        /// <typeparam name="TValue">The type of the property's value.</typeparam>
        /// <param name="name">The name of the property.</param>
        /// <param name="defaultValue">The default value of the property.</param>
        /// <param name="inherits">Whether the property inherits its value.</param>
        /// <param name="defaultBindingMode">The default binding mode for the property.</param>
        /// <returns>A <see cref="PerspexProperty{TValue}"/></returns>
        public static PerspexProperty <TValue> RegisterAttached <TOwner, THost, TValue>(
            string name,
            TValue defaultValue            = default(TValue),
            bool inherits                  = false,
            BindingMode defaultBindingMode = BindingMode.OneWay)
            where TOwner : PerspexObject
        {
            Contract.Requires <NullReferenceException>(name != null);

            PerspexProperty <TValue> result = new PerspexProperty <TValue>(
                typeof(TOwner) + "." + name,
                typeof(TOwner),
                defaultValue,
                inherits,
                defaultBindingMode);

            PerspexObject.Register(typeof(THost), result);

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Registers an attached <see cref="PerspexProperty"/>.
        /// </summary>
        /// <typeparam name="TOwner">The type of the class that is registering the property.</typeparam>
        /// <typeparam name="THost">The type of the class that the property is to be registered on.</typeparam>
        /// <typeparam name="TValue">The type of the property's value.</typeparam>
        /// <param name="name">The name of the property.</param>
        /// <param name="defaultValue">The default value of the property.</param>
        /// <param name="inherits">Whether the property inherits its value.</param>
        /// <param name="defaultBindingMode">The default binding mode for the property.</param>
        /// <param name="validate">A validation function.</param>
        /// <returns>A <see cref="PerspexProperty{TValue}"/></returns>
        public static PerspexProperty <TValue> RegisterAttached <TOwner, THost, TValue>(
            string name,
            TValue defaultValue            = default(TValue),
            bool inherits                  = false,
            BindingMode defaultBindingMode = BindingMode.OneWay,
            Func <PerspexObject, TValue, TValue> validate = null)
        {
            Contract.Requires <ArgumentNullException>(name != null);

            PerspexProperty <TValue> result = new PerspexProperty <TValue>(
                name,
                typeof(TOwner),
                defaultValue,
                inherits,
                defaultBindingMode,
                validate,
                null,
                true);

            PerspexObject.Register(typeof(THost), result);

            return(result);
        }
Beispiel #7
0
 /// <summary>
 /// Registers the property on another type.
 /// </summary>
 /// <typeparam name="TOwner">The type of the additional owner.</typeparam>
 /// <returns>The property.</returns>
 public PerspexProperty <TValue> AddOwner <TOwner>()
 {
     PerspexObject.Register(typeof(TOwner), this);
     return(this);
 }