示例#1
0
        /// <summary>
        /// Enumerates through element's parents in the visual tree.
        /// </summary>
        public static IEnumerable <DependencyObject> GetParents(this DependencyObject element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            while ((element = element.GetParent()) != null)
            {
                yield return(element);
            }
        }
示例#2
0
        /// <summary>
        /// This works like FrameworkElement.FindName only in reverse up the tree instead of down
        ///         - http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname.aspx
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object FindNameUpTree(this System.Windows.DependencyObject child, string controlToFindName)
        {
            System.Windows.DependencyObject current = child;
            string currentName = null;

            do
            {
                current     = current.GetParent();
                currentName = current.GetValue(System.Windows.Controls.Control.NameProperty) as string; // if it doesn't have one this should be null right???
            } while ((current != null) && !string.Equals(currentName, controlToFindName));

            return(current);
        }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Property property = item as Property;
            if (property == null)
            {
                throw new ArgumentException("item must be of type Property");
            }

            DataTemplate template = null;

            //search for template in ConfigPropertyGridDataTemplates, specifically datatemplates for FilePath and DirectoryPath

            //if parent window is MainWindow just use ConfigPropertyGridDataTemplates
            var window = container.GetParent<TraceLab.UI.WPF.Views.MainWindow>(null);
            if (window != null)
            {
                template = FindDataTemplate(property, new ConfigPathsDataTemplates());
            }
            else
            {
                //if parent window is a benchmark window use ConfigPropertyGridDataTemplatesBenchmark
                //the only difference are bindings to the experiment path 
                var benchmarkWizardWindow = container.GetParent<TraceLab.UI.WPF.Views.BenchmarkWizardDialog>(null);
                if (benchmarkWizardWindow != null)
                {
                    template = FindDataTemplate(property, new ConfigPathsDataTemplatesBenchmark());
                }
            }

            //otherwise use base template selector
            if (template == null)
            {
                template = base.SelectTemplate(item, container);
            }

            return template;
        }
        /// <summary>
        /// Tries the find experiment.
        /// </summary>
        /// <param name="dependencyObject">The dependency object from which the parent is going to be searched for</param>
        /// <param name="experiment">The experiment.</param>
        /// <returns></returns>
        protected static bool TryFindExperiment(DependencyObject dependencyObject, out IExperiment experiment)
        {
            bool found = false;
            experiment = null;

            if (dependencyObject != null)
            {
                var nodeInfoContainer = dependencyObject.GetParent<TraceLab.UI.WPF.Views.Nodes.NodeInfoContainer>(null);

                var componentNodeInfo = nodeInfoContainer.DataContext as ExperimentNodeInfo;
                if (componentNodeInfo != null)
                {
                    experiment = componentNodeInfo.Node.Owner;
                    found = true;
                }
            }

            return found;
        }