/// <summary>
 /// Initializes a new instance of the <see cref="BindingError"/> class.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <param name="binding">The binding.</param>
 /// <param name="message">The message.</param>
 public BindingError(IElement item, BoundType type, DependencyProperty property, Binding binding, string message)
 {
     _element = item;
     _type = type;
     _property = property;
     _binding = binding;
     _message = message;
 }
Exemple #2
0
        /// <summary>
        /// Creates a data bound element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="baseName">A base name.</param>
        /// <param name="checkLogicalChildren">Indicate whether this elements children should be checked.</param>
        /// <returns></returns>
		public static IBoundElement DependencyObject(DependencyObject element, BoundType boundType, string baseName,
                                                bool checkLogicalChildren)
        {
            var dependencyObjectElement = new DependencyObjectElement(element, boundType, baseName)
            {
                CheckLogicalChildren = checkLogicalChildren
            };
            return dependencyObjectElement;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
        /// </summary>
        /// <param name="dataTemplate">The data template.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="baseName">Name of the base.</param>
        internal DataTemplateElement(DataTemplate dataTemplate, BoundType boundType, string baseName)
            : base(dataTemplate.LoadContent(), boundType)
        {
            _dataTemplate = dataTemplate;

            if(_dataTemplate.DataTemplateKey != null)
                BaseName = baseName + " [DataTemplate " + _dataTemplate.DataTemplateKey + "] ";

            else BaseName = baseName + " [DataTemplate] ";
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
        /// </summary>
        /// <param name="controlTemplate">The data template.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="baseName">Name of the base.</param>
        internal ControlTemplateElement(ControlTemplate controlTemplate, BoundType boundType, string baseName)
            : base(controlTemplate.LoadContent(), boundType)
        {
            _controlTemplate = controlTemplate;

            if(_controlTemplate.TargetType != null)
                BaseName = baseName + " [ControlTemplate " + _controlTemplate.TargetType.Name + "] ";

            else BaseName = baseName + " [ControlTemplate] ";
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DependencyObjectElement"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="baseName">Name of the base.</param>
        internal DependencyObjectElement(DependencyObject element, BoundType boundType, string baseName)
        {
            _element = element;
            _type = EnsureBoundType(boundType);

            if(_type != boundType && _type != null)
                _dataContextCheckType = boundType;

            BaseName = baseName ?? string.Empty;
        }
Exemple #6
0
 /// <summary>
 /// Creates a "bad data context" error.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <returns></returns>
 public static IError BadDataContext(IElement item, BoundType type, DependencyProperty property)
 {
     return new BindingError(
         item,
         type,
         property,
         null,
         string.Format(
             "[{0}] The data context was not valid.",
             item.Name
             )
         );
 }
Exemple #7
0
 /// <summary>
 /// Creates a "bad property" error.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <param name="binding">The binding.</param>
 /// <returns></returns>
 public static IError BadProperty(IElement item, BoundType type, DependencyProperty property, Binding binding)
 {
     return new BindingError(
         item,
         type,
         property,
         binding,
         string.Format(
             "[{0}] The property '{1}' was not found on '{2}'.",
             item.Name,
             binding.Path.Path,
             type.Type.Name
             )
         );
 }
        /// <summary>
        /// Gets the bound property.
        /// </summary>
        /// <param name="propertyValue">The property value.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="baseName">A base name.</param>
        /// <returns>Returns an instance of <see cref="IElement"/> if the property should be checked, otherwise null.</returns>
        public IElement GetBoundProperty(object propertyValue, BoundType boundType, string baseName)
        {
            if(propertyValue is Style)
            {
                if(IncludeStyles)
                {
                    return Bound.Style((Style)propertyValue, boundType, baseName);
                }
            }

            else if(propertyValue is DataTemplate)
            {
                if(IncludeTemplates)
                {
                    var template = (DataTemplate)propertyValue;
                    var dataType = template.DataType as Type;

                    if(dataType == null) return null;
                    return Bound.DataTemplate(template, new BoundType(dataType), baseName);
                }
            }

            else if(propertyValue is ControlTemplate)
            {
                if(IncludeTemplates)
                {
                    var template = (ControlTemplate)propertyValue;
                    return Bound.ControlTemplate(template, boundType, baseName);
                }
            }

            else if(propertyValue is UserControl)
            {
                return Bound.DependencyObject((UserControl)propertyValue, boundType, baseName + ".",
                                              TraverseUserControls);
            }

            else if(propertyValue is IEnumerable)
            {
                if(IncludeAllDependencyObjects)
                    return Bound.Enumerable((IEnumerable)propertyValue, boundType, baseName + ".");
            }
            else if(propertyValue is DependencyObject && IncludeAllDependencyObjects)
                return Bound.DependencyObject((DependencyObject)propertyValue, boundType, baseName + ".");

            return null;
        }
Exemple #9
0
 /// <summary>
 /// Creates an enumerable error.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <param name="binding">The binding.</param>
 /// <returns></returns>
 public static IError NotEnumerable(IElement item, BoundType type, DependencyProperty property, Binding binding)
 {
     return new BindingError(
         item,
         type,
         property,
         binding,
         string.Format(
             "[{0}] The property '{1}' on '{2}' is not an IEnumerable, which is required by {3} on {4}.",
             item.Name,
             binding.Path.Path,
             type.Type.Name,
             property.Name,
             property.OwnerType.Name
             )
         );
 }
Exemple #10
0
 /// <summary>
 /// Creates an enumerable error.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="property">The property.</param>
 /// <param name="binding">The binding.</param>
 /// <returns></returns>
 public static IError NotEnumerable(IElement item, BoundType type, DependencyProperty property, Binding binding)
 {
     return(new BindingError(
                item,
                type,
                property,
                binding,
                string.Format(
                    "[{0}] The property '{1}' on '{2}' is not an IEnumerable, which is required by {3} on {4}.",
                    item.Name,
                    binding.Path.Path,
                    type.Type.Name,
                    property.Name,
                    property.OwnerType.Name
                    )
                ));
 }
        /// <summary>
        /// Ensures that the type is accurately represented.
        /// </summary>
        /// <param name="boundType">Type of the bound.</param>
        /// <returns></returns>
        protected BoundType EnsureBoundType(BoundType boundType)
        {
            var frameworkElement = element as FrameworkElement;

            if (frameworkElement != null)
            {
                var binding = BindingOperations.GetBinding(
                    element,
                    FrameworkElement.DataContextProperty
                    );

                if (binding.ShouldValidate())
                {
                    var propertyPath = binding.Path.Path;
                    return(boundType.GetAssociatedType(propertyPath));
                }
            }

            return(boundType);
        }
Exemple #12
0
 /// <summary>
 /// Creates a bound control template.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="boundType">Type of the bound object.</param>
 /// <param name="baseName">A base name.</param>
 /// <returns></returns>
 public static IBoundElement ControlTemplate(ControlTemplate template, BoundType boundType, string baseName)
 {
     return(new ControlTemplateElement(template, boundType, baseName));
 }
Exemple #13
0
 /// <summary>
 /// Creates a bound style.
 /// </summary>
 /// <param name="style">The style.</param>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 public static IBoundElement Style(Style style, BoundType type)
 {
     return(Style(style, type, string.Empty));
 }
Exemple #14
0
 /// <summary>
 /// Creates an ambiguous template error.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="type">The type.</param>
 /// <param name="templatePropertyName">The name of the template property.</param>
 /// <returns></returns>
 public static IError TemplateSelectorAmbiguity(IElement item, BoundType type, string templatePropertyName)
 {
     return new GeneralError(
         item,
         type,
         string.Format(
             "[{0}] {1} ambiguity.  You can either set a TemplateSelector or a DataTemplate, but not both.",
             item.Name,
             templatePropertyName
             )
         );
 }
Exemple #15
0
 /// <summary>
 /// Creates a bound data template.
 /// </summary>
 /// <param name="dataTemplate">The data template.</param>
 /// <param name="boundType">Type of the bound.</param>
 /// <returns></returns>
 public static IBoundElement DataTemplate(DataTemplate dataTemplate, BoundType boundType)
 {
     return(DataTemplate(dataTemplate, boundType, string.Empty));
 }
Exemple #16
0
        /// <summary>
        /// Creates a bound enumerable.
        /// </summary>
        /// <param name="enumerable">The enumerable.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
		public static IBoundElement Enumerable(IEnumerable enumerable, BoundType boundType, string name)
        {
            return new EnumerableElement(enumerable, boundType, name);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
 /// </summary>
 /// <param name="controlTemplate">The data template.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal ControlTemplateElement(ControlTemplate controlTemplate, BoundType boundType)
     : this(controlTemplate, boundType, string.Empty) {}
		protected override void given_the_context_of()
		{
			_boundType = new BoundType(typeof(MyPresenter));
		}
Exemple #19
0
        /// <summary>
        /// Creates a data bound element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="baseName">A base name.</param>
        /// <returns></returns>
		public static IBoundElement DependencyObject(DependencyObject element, BoundType boundType, string baseName)
        {
            return DependencyObject(element, boundType, baseName, true);
        }
Exemple #20
0
        /// <summary>
        /// Creates a bound control template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="baseName">A base name.</param>
        /// <returns></returns>
		public static IBoundElement ControlTemplate(ControlTemplate template, BoundType boundType, string baseName)
        {
            return new ControlTemplateElement(template, boundType, baseName);
        }
Exemple #21
0
        /// <summary>
        /// Creates a bound style.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
		public static IBoundElement Style(Style style, BoundType type)
        {
            return Style(style, type, string.Empty);
        }
Exemple #22
0
        /// <summary>
        /// Creates a bound data template.
        /// </summary>
        /// <param name="dataTemplate">The data template.</param>
        /// <param name="boundType">Type of the bound object.</param>
        /// <param name="baseName">A base name.</param>
        /// <returns></returns>
		public static IBoundElement DataTemplate(DataTemplate dataTemplate, BoundType boundType, string baseName)
        {
            if(!dataTemplate.IsSealed) dataTemplate.Seal();
            return new DataTemplateElement(dataTemplate, boundType, baseName);
        }
Exemple #23
0
        /// <summary>
        /// Creates a bound data template.
        /// </summary>
        /// <param name="dataTemplate">The data template.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <returns></returns>
		public static IBoundElement DataTemplate(DataTemplate dataTemplate, BoundType boundType)
        {
            return DataTemplate(dataTemplate, boundType, string.Empty);
        }
Exemple #24
0
        /// <summary>
        /// Creates a bound group style.
        /// </summary>
        /// <param name="groupStyle">The group style.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
		public static IBoundElement GroupStyle(GroupStyle groupStyle, BoundType type)
        {
            return GroupStyle(groupStyle, type, string.Empty);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TriggerValidator"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="item">The item.</param>
 /// <param name="triggers">The triggers.</param>
 public TriggerValidator(BoundType type, IElement item, TriggerCollection triggers)
 {
     this.item     = item;
     this.type     = type;
     this.triggers = triggers;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObjectElement"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal DependencyObjectElement(DependencyObject element, BoundType boundType)
     : this(element, boundType, string.Empty)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
 /// </summary>
 /// <param name="dataTemplate">The data template.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal DataTemplateElement(DataTemplate dataTemplate, BoundType boundType)
     : this(dataTemplate, boundType, string.Empty)
 {
 }
Exemple #28
0
 /// <summary>
 /// Creates a data bound element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="boundType">Type of the bound object.</param>
 /// <returns></returns>
 public static IBoundElement DependencyObject(DependencyObject element, BoundType boundType)
 {
     return DependencyObject(element, boundType, string.Empty);
 }
Exemple #29
0
        /// <summary>
        /// Creates a bound style.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
		public static IBoundElement Style(Style style, BoundType type, string name)
        {
            if(!style.IsSealed) style.Seal();
            return new StyleElement(style, type, name);
        }
Exemple #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EnumerableElement"/> class.
 /// </summary>
 /// <param name="enumerable">The enumerable.</param>
 /// <param name="boundType">Type of the bound.</param>
 /// <param name="name">The name.</param>
 internal EnumerableElement(IEnumerable enumerable, BoundType boundType, string name)
 {
     this.enumerable = enumerable;
     type            = boundType;
     this.name       = name;
 }
Exemple #31
0
 /// <summary>
 /// Creates a bound group style.
 /// </summary>
 /// <param name="groupStyle">The group style.</param>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 public static IBoundElement GroupStyle(GroupStyle groupStyle, BoundType type)
 {
     return(GroupStyle(groupStyle, type, string.Empty));
 }
Exemple #32
0
        /// <summary>
        /// Creates a bound group style.
        /// </summary>
        /// <param name="groupStyle">The group style.</param>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
		public static IBoundElement GroupStyle(GroupStyle groupStyle, BoundType type, string name)
        {
            return new GroupStyleElement(groupStyle, type, name);
        }
        /// <summary>
        /// Ensures that the type is accurately represented.
        /// </summary>
        /// <param name="boundType">Type of the bound.</param>
        /// <returns></returns>
        protected BoundType EnsureBoundType(BoundType boundType)
        {
            var frameworkElement = _element as FrameworkElement;

            if(frameworkElement != null)
            {
                var binding = BindingOperations.GetBinding(
                    _element,
                    FrameworkElement.DataContextProperty
                    );

                if(binding.ShouldValidate())
                {
                    var propertyPath = binding.Path.Path;
                    return boundType.GetAssociatedType(propertyPath);
                }
            }

            return boundType;
        }
Exemple #34
0
 /// <summary>
 /// Creates a bound group style.
 /// </summary>
 /// <param name="groupStyle">The group style.</param>
 /// <param name="type">The type.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static IBoundElement GroupStyle(GroupStyle groupStyle, BoundType type, string name)
 {
     return(new GroupStyleElement(groupStyle, type, name));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObjectElement"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal DependencyObjectElement(DependencyObject element, BoundType boundType)
     : this(element, boundType, string.Empty) {}
 /// <summary>
 /// Initializes a new instance of the <see cref="StyleElement"/> class.
 /// </summary>
 /// <param name="style">The style.</param>
 /// <param name="boundType">Type of the bound.</param>
 /// <param name="name">The name.</param>
 internal GroupStyleElement(GroupStyle style, BoundType boundType, string name)
 {
     _style = style;
     _type = boundType;
     _name = name + " [GroupStyle] ";
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TriggerValidator"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="item">The item.</param>
 /// <param name="triggers">The triggers.</param>
 public TriggerValidator(BoundType type, IElement item, TriggerCollection triggers)
 {
     this.item = item;
     _type = type;
     _triggers = triggers;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EnumerableElement"/> class.
 /// </summary>
 /// <param name="enumerable">The enumerable.</param>
 /// <param name="boundType">Type of the bound.</param>
 /// <param name="name">The name.</param>
 internal EnumerableElement(IEnumerable enumerable, BoundType boundType, string name)
 {
     _enumerable = enumerable;
     _type = boundType;
     _name = name;
 }
Exemple #39
0
 /// <summary>
 /// Creates a bound enumerable.
 /// </summary>
 /// <param name="enumerable">The enumerable.</param>
 /// <param name="boundType">Type of the bound object.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static IBoundElement Enumerable(IEnumerable enumerable, BoundType boundType, string name)
 {
     return(new EnumerableElement(enumerable, boundType, name));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
 /// </summary>
 /// <param name="dataTemplate">The data template.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal DataTemplateElement(DataTemplate dataTemplate, BoundType boundType)
     : this(dataTemplate, boundType, string.Empty) {}
Exemple #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StyleElement"/> class.
 /// </summary>
 /// <param name="style">The style.</param>
 /// <param name="boundType">Type of the bound.</param>
 /// <param name="name">The name.</param>
 internal StyleElement(Style style, BoundType boundType, string name)
 {
     this.style = style;
     type       = boundType;
     this.name  = name + " [Style] ";
 }
Exemple #42
0
 /// <summary>
 /// Creates a data bound element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="boundType">Type of the bound object.</param>
 /// <returns></returns>
 public static IBoundElement DependencyObject(DependencyObject element, BoundType boundType)
 {
     return(DependencyObject(element, boundType, string.Empty));
 }
Exemple #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataTemplateElement"/> class.
 /// </summary>
 /// <param name="controlTemplate">The data template.</param>
 /// <param name="boundType">Type of the bound.</param>
 internal ControlTemplateElement(ControlTemplate controlTemplate, BoundType boundType)
     : this(controlTemplate, boundType, string.Empty)
 {
 }
Exemple #44
0
 /// <summary>
 /// Creates a data bound element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="boundType">Type of the bound object.</param>
 /// <param name="baseName">A base name.</param>
 /// <returns></returns>
 public static IBoundElement DependencyObject(DependencyObject element, BoundType boundType, string baseName)
 {
     return(DependencyObject(element, boundType, baseName, true));
 }