コード例 #1
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable <IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            if (Type == null)
            {
                yield break;
            }

            if (style.ContainerStyle != null)
            {
                var target = style.ContainerStyle.TargetType != null
                                 ? new BoundType(style.ContainerStyle.TargetType)
                                 : new BoundType(typeof(GroupItem));

                yield return(Bound.Style(style.ContainerStyle, target, Name));
            }

            if (style.HeaderTemplate != null)
            {
                var target = style.HeaderTemplate.DataType as Type != null
                                 ? new BoundType(style.HeaderTemplate.DataType as Type)
                                 : new BoundType(typeof(GroupItem));

                yield return(Bound.DataTemplate(style.HeaderTemplate, target, Name));
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets the children.
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 /// <value>The children.</value>
 public IEnumerable<IElement> GetChildren(ElementEnumeratorSettings settings)
 {
     foreach(var item in _enumerable)
     {
         var element = settings.GetBoundProperty(item, Type, Name);
         if(element != null) yield return element;
     }
 }
コード例 #3
0
 /// <summary>
 /// Gets the children.
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 /// <value>The children.</value>
 public IEnumerable <IElement> GetChildren(ElementEnumeratorSettings settings)
 {
     foreach (var item in enumerable)
     {
         var element = settings.GetBoundProperty(item, Type, Name);
         if (element != null)
         {
             yield return(element);
         }
     }
 }
コード例 #4
0
ファイル: StyleElement.cs プロジェクト: ssethi/TestFrameworks
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable<IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            foreach(var setterBase in _style.Setters)
            {
                var setter = setterBase as Setter;

                if(setter == null) continue;
                if(setter.Value is BindingBase) continue;

                var dataBound = settings.GetBoundProperty(setter.Value, Type, Name);

                if(dataBound != null)
                    yield return dataBound;
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable<IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            if(Type == null) yield break;

            if(_style.ContainerStyle != null)
            {
                var target = _style.ContainerStyle.TargetType != null
                                 ? new BoundType(_style.ContainerStyle.TargetType)
                                 : new BoundType(typeof(GroupItem));

                yield return Bound.Style(_style.ContainerStyle, target, Name);
            }

            if(_style.HeaderTemplate != null)
            {
                var target = _style.HeaderTemplate.DataType as Type != null
                                 ? new BoundType(_style.HeaderTemplate.DataType as Type)
                                 : new BoundType(typeof(GroupItem));

                yield return Bound.DataTemplate(_style.HeaderTemplate, target, Name);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable <IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            foreach (var setterBase in style.Setters)
            {
                var setter = setterBase as Setter;

                if (setter == null)
                {
                    continue;
                }
                if (setter.Value is BindingBase)
                {
                    continue;
                }

                var dataBound = settings.GetBoundProperty(setter.Value, Type, Name);

                if (dataBound != null)
                {
                    yield return(dataBound);
                }
            }
        }
コード例 #7
0
        private IEnumerable<IElement> CheckHeaderedItemsControl(ICollection<string> checkedProperties,
                                                                ElementEnumeratorSettings settings)
        {
            if(!settings.IncludeTemplates) yield break;

            var headeredItemsControl = Element as HeaderedItemsControl;

            if(headeredItemsControl != null)
            {
                checkedProperties.Add(HeaderedContentControl.HeaderTemplateProperty.Name);

                var template = headeredItemsControl.HeaderTemplate;

                if(template != null)
                {
                    var dataType = template.DataType as Type;

                    if(dataType == null)
                    {
                        var binding = BindingOperations.GetBinding(
                            headeredItemsControl,
                            HeaderedItemsControl.HeaderProperty
                            );

                        if(binding != null)
                            yield return Bound.DataTemplate(template, Type.GetAssociatedType(binding.Path.Path), Name);
                    }
                    else yield return Bound.DataTemplate(template, new BoundType(dataType), Name);
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ElementEnumerator"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 public ElementEnumerator(IElement element)
 {
     this.element = element;
     settings     = new ElementEnumeratorSettings();
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ElementEnumerator"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 public ElementEnumerator(IElement element)
 {
     _element = element;
     _settings = new ElementEnumeratorSettings();
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StyleValidator"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="element">The element.</param>
 public StyleValidator(ElementEnumeratorSettings settings, StyleElement element)
 {
     this.settings = settings;
     this.element  = element;
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObjectValidator"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="element">The element.</param>
 public DependencyObjectValidator(ElementEnumeratorSettings settings, DependencyObjectElement element)
 {
     this.settings = settings;
     this.element  = element;
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObjectValidator"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="element">The element.</param>
 public DependencyObjectValidator(ElementEnumeratorSettings settings, DependencyObjectElement element)
 {
     _settings = settings;
     _element = element;
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StyleValidator"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="element">The element.</param>
 public StyleValidator(ElementEnumeratorSettings settings, StyleElement element)
 {
     _settings = settings;
     _element = element;
 }
コード例 #14
0
        private IEnumerable<IElement> CheckItemsControl(ICollection<string> checkedProperties,
                                                        ElementEnumeratorSettings settings)
        {
            var itemsControl = Element as ItemsControl;

            if(itemsControl != null)
            {
                checkedProperties.Add(ItemsControl.ItemTemplateProperty.Name);

                var template = itemsControl.ItemTemplate;

                if(template != null && settings.IncludeTemplates)
                {
                    var dataType = template.DataType as Type;

                    if(dataType == null)
                    {
                        var binding = BindingOperations.GetBinding(
                            itemsControl,
                            ItemsControl.ItemsSourceProperty
                            );

                        if(binding != null)
                        {
                            var enumerableType = Type.GetPropertyType(binding.Path.Path);

							if (enumerableType != null)
                            {   
                                var generics = enumerableType.GetGenericArguments();

                                if(generics != null && generics.Length == 1)
                                    yield return Bound.DataTemplate(template, new BoundType(generics[0]), Name);
                            }
                        }
                    }
                    else yield return Bound.DataTemplate(template, new BoundType(dataType), Name);
                }

                if(settings.IncludeStyles)
                {
                    if(itemsControl.ItemContainerStyle != null)
                    {
                        checkedProperties.Add(ItemsControl.ItemContainerStyleProperty.Name);
                        yield return Bound.Style(itemsControl.ItemContainerStyle, Type, Name);
                    }

                    foreach(var groupStyle in itemsControl.GroupStyle)
                    {
                        checkedProperties.Add("GroupStyle");
                        yield return Bound.GroupStyle(groupStyle, Type, Name);
                    }
                }

                foreach(var item in CheckHeaderedItemsControl(checkedProperties, settings))
                {
                    yield return item;
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable<IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            if(Type == null) yield break;

            var checkedProperties = new List<string>();

            foreach(var item in CheckContentControl(checkedProperties, settings))
            {
                yield return item;
            }

            foreach(var item in CheckItemsControl(checkedProperties, settings))
            {
                yield return item;
            }

            var logicalChildren = LogicalTreeHelper.GetChildren(Element).Cast<object>().ToList();
            var enumerator = _element.GetLocalValueEnumerator();

            while(enumerator.MoveNext())
            {
                var entry = enumerator.Current;

                if(BindingOperations.IsDataBound(_element, entry.Property)) continue;
                if(checkedProperties.Contains(entry.Property.Name)) continue;
                if(logicalChildren.Contains(entry.Value)) continue;

                var dataBound = settings.GetBoundProperty(entry.Value, Type, Name);

                if(dataBound != null)
                    yield return dataBound;
            }

            if(!CheckLogicalChildren) yield break;

            foreach(var child in logicalChildren)
            {
                if(child is DependencyObject)
                {
                    yield return Bound.DependencyObject(
                        child as DependencyObject,
                        Type, Name + ".",
                        (settings.TraverseUserControls || !(child is UserControl))
                        );
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <value>The children.</value>
        public IEnumerable <IElement> GetChildren(ElementEnumeratorSettings settings)
        {
            if (Type == null)
            {
                yield break;
            }

            var checkedProperties = new List <string>();

            foreach (var item in CheckContentControl(checkedProperties, settings))
            {
                yield return(item);
            }

            foreach (var item in CheckItemsControl(checkedProperties, settings))
            {
                yield return(item);
            }

            var logicalChildren = LogicalTreeHelper.GetChildren(Element).Cast <object>().ToList();
            var enumerator      = element.GetLocalValueEnumerator();

            while (enumerator.MoveNext())
            {
                var entry = enumerator.Current;

                if (BindingOperations.IsDataBound(element, entry.Property))
                {
                    continue;
                }
                if (checkedProperties.Contains(entry.Property.Name))
                {
                    continue;
                }
                if (logicalChildren.Contains(entry.Value))
                {
                    continue;
                }

                var dataBound = settings.GetBoundProperty(entry.Value, Type, Name);

                if (dataBound != null)
                {
                    yield return(dataBound);
                }
            }

            if (!CheckLogicalChildren)
            {
                yield break;
            }

            foreach (var child in logicalChildren)
            {
                if (child is DependencyObject)
                {
                    yield return(Bound.DependencyObject(
                                     child as DependencyObject,
                                     Type, Name + ".",
                                     (settings.TraverseUserControls || !(child is UserControl))
                                     ));
                }
            }
        }
コード例 #17
0
        IEnumerable <IElement> CheckHeaderedItemsControl(ICollection <string> checkedProperties, ElementEnumeratorSettings settings)
        {
            if (!settings.IncludeTemplates)
            {
                yield break;
            }

            var headeredItemsControl = Element as HeaderedItemsControl;

            if (headeredItemsControl != null)
            {
                checkedProperties.Add(HeaderedContentControl.HeaderTemplateProperty.Name);

                var template = headeredItemsControl.HeaderTemplate;

                if (template != null)
                {
                    var dataType = template.DataType as Type;

                    if (dataType == null)
                    {
                        var binding = BindingOperations.GetBinding(
                            headeredItemsControl,
                            HeaderedItemsControl.HeaderProperty
                            );

                        if (binding != null)
                        {
                            yield return(Bound.DataTemplate(template, Type.GetAssociatedType(binding.Path.Path), Name));
                        }
                    }
                    else
                    {
                        yield return(Bound.DataTemplate(template, new BoundType(dataType), Name));
                    }
                }
            }
        }
コード例 #18
0
        IEnumerable <IElement> CheckItemsControl(ICollection <string> checkedProperties, ElementEnumeratorSettings settings)
        {
            var itemsControl = Element as ItemsControl;

            if (itemsControl != null)
            {
                checkedProperties.Add(ItemsControl.ItemTemplateProperty.Name);

                var template = itemsControl.ItemTemplate;

                if (template != null && settings.IncludeTemplates)
                {
                    var dataType = template.DataType as Type;

                    if (dataType == null)
                    {
                        var binding = BindingOperations.GetBinding(
                            itemsControl,
                            ItemsControl.ItemsSourceProperty
                            );

                        if (binding != null)
                        {
                            var enumerableType = Type.GetPropertyType(binding.Path.Path);

                            if (enumerableType != null)
                            {
                                var generics = enumerableType.GetGenericArguments();

                                if (generics != null && generics.Length == 1)
                                {
                                    yield return(Bound.DataTemplate(template, new BoundType(generics[0]), Name));
                                }
                            }
                        }
                    }
                    else
                    {
                        yield return(Bound.DataTemplate(template, new BoundType(dataType), Name));
                    }
                }

                if (settings.IncludeStyles)
                {
                    if (itemsControl.ItemContainerStyle != null)
                    {
                        checkedProperties.Add(ItemsControl.ItemContainerStyleProperty.Name);
                        yield return(Bound.Style(itemsControl.ItemContainerStyle, Type, Name));
                    }

                    foreach (var groupStyle in itemsControl.GroupStyle)
                    {
                        checkedProperties.Add("GroupStyle");
                        yield return(Bound.GroupStyle(groupStyle, Type, Name));
                    }
                }

                foreach (var item in CheckHeaderedItemsControl(checkedProperties, settings))
                {
                    yield return(item);
                }
            }
        }