private static IEnumerable<ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue<DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention }; } foreach (object child in LogicalTreeHelper.GetChildren(current)) { var childDo = child as DependencyObject; if (childDo == null || childDo is UserControl) continue; queue.Enqueue(childDo); } } }
/// <summary> /// Finds the interaction defaults or fail. /// </summary> /// <param name="conventionManager">The convention manager.</param> /// <param name="element">The element.</param> /// <returns></returns> public static IElementConvention FindElementConventionOrFail(this IConventionManager conventionManager, object element) { var type = element.GetType(); var defaults = conventionManager.GetElementConvention(type); if (defaults == null) { throw new CaliburnException( string.Format("Could not locate an IElementConvention for {0}. Please register one with the IConventionManager.", type.Name) ); } return(defaults); }
private static IEnumerable <ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue <DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) { yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention } } ; } foreach (object child in LogicalTreeHelper.GetChildren(current)) { var childDo = child as DependencyObject; if (childDo == null || childDo is UserControl) { continue; } queue.Enqueue(childDo); } } }
private static IEnumerable<ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue<DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention }; } var childCount = VisualTreeHelper.GetChildrenCount(current); if (childCount > 0) { for(var i = 0; i < childCount; i++) { var childDo = VisualTreeHelper.GetChild(current, i); if(childDo is UserControl) continue; queue.Enqueue(childDo); } } else { var contentControl = current as ContentControl; if (contentControl != null) { if (contentControl.Content != null && contentControl.Content is DependencyObject && !(contentControl.Content is UserControl)) queue.Enqueue(contentControl.Content as DependencyObject); } else { var itemsControl = current as ItemsControl; if(itemsControl != null) { itemsControl.Items.OfType<DependencyObject>() .Where(item => !(item is UserControl)) .Apply(queue.Enqueue); } } } } }
private static IEnumerable <ElementDescription> DefaultSelectElementsToInspectImplementation(IConventionManager conventionManager, DependencyObject root) { var queue = new Queue <DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); var currentName = current.GetName(); if (!string.IsNullOrEmpty(currentName)) { var currentType = current.GetType(); var currentConvention = conventionManager.GetElementConvention(currentType); if (currentConvention != null) { yield return new ElementDescription { Type = currentType, Name = currentName, Convention = currentConvention } } ; } var childCount = VisualTreeHelper.GetChildrenCount(current); if (childCount > 0) { for (var i = 0; i < childCount; i++) { var childDo = VisualTreeHelper.GetChild(current, i); if (childDo is UserControl) { continue; } queue.Enqueue(childDo); } } else { var contentControl = current as ContentControl; if (contentControl != null) { if (contentControl.Content != null && contentControl.Content is DependencyObject && !(contentControl.Content is UserControl)) { queue.Enqueue(contentControl.Content as DependencyObject); } } else { var itemsControl = current as ItemsControl; if (itemsControl != null) { itemsControl.Items.OfType <DependencyObject>() .Where(item => !(item is UserControl)) .Apply(queue.Enqueue); } } } } }