本文整理汇总了C#中System.Windows.DependencyObject.GetParent方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetParent方法的具体用法?C# DependencyObject.GetParent怎么用?C# DependencyObject.GetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectTemplate
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;
}
示例2: TryFindExperiment
/// <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;
}