Beispiel #1
0
        public static T Clone <T>(this T subject)
            where T : BindingBase
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            T            result = null;
            Binding      subjectAsBinding;
            MultiBinding subjectAsMultiBinding;
            ICloneable   subjectAsICloneable;

            if ((subjectAsBinding = subject as Binding) != null)
            {
                result = BindingExtensions.Clone(subjectAsBinding, null, null, null) as T;
            }
            else if ((subjectAsMultiBinding = subject as MultiBinding) != null)
            {
                result = MultiBindingExtensions.Clone(subjectAsMultiBinding) as T;
            }
            else if ((subjectAsICloneable = subject as ICloneable) != null)
            {
                result = subjectAsICloneable.Clone() as T;
            }

            if (result != null)
            {
                return(result);
            }

            throw new NotSupportedException(String.Format("The binding type {0} is not supported for cloning.", subject.GetType()));
        }
Beispiel #2
0
        /// <summary>
        /// Returns a clone of this binding but with a different value for the 'ElementName' property.
        /// Using this method is required if you wish to set a ElementName and the original binding uses
        /// RelativeSource or Source.
        /// </summary>
        /// <param name="subject">The binding.</param>
        /// <param name="newElementName">The new value for ElementName.</param>
        /// <returns>The clone.</returns>
        public static Binding Clone(this Binding subject, string newElementName)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            return(BindingExtensions.Clone(subject, null, null, newElementName));
        }
Beispiel #3
0
        /// <summary>
        /// Returns a clone of this binding but with a different value for the 'RelativeSource' property.
        /// Using this method is required if you wish to set a RelativeSource and the original binding uses
        /// ElementName or Source.
        /// </summary>
        /// <param name="subject">The binding.</param>
        /// <param name="newRelativeSource">The new value for RelativeSource.</param>
        /// <returns>The clone.</returns>
        public static Binding Clone(this Binding subject, RelativeSource newRelativeSource)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            return(BindingExtensions.Clone(subject, null, newRelativeSource, null));
        }