访问windows.resources中的文本框

时间:2011-11-03 10:20:54

标签: c# wpf

我在window.resources的分层模板中有一个名为=“TextboxA”的文本框。在C#方面,如何访问分层数据模板中的特定文本框?

1 个答案:

答案 0 :(得分:1)

首先需要引用正在模板化的项目,以便获得该控件的实例,在任何时候都可能存在相当多的实例。然后你可以得到模板并尝试find(读这个!)模板化项目上的元素:

var template = (HierarchicalDataTemplate)FindResource("ResourceKeyOfTemplate");
FrameworkElement templatedParent = /* Needs a reference to the templated parent here */;
var textbox = (TextBox)template.FindName("TextboxA", templatedParent);
相关问题