我有DataTemplate
,后面需要一些代码。此模板包含例如属性为ListBox
的{{1}}。此模板位于x:Name="myListBox"
,其中包含属性ResourceDictionary
。现在,我如何才能从x:Class="MyNamespace.MyClass"
的代码访问MyClass
实例?
答案 0 :(得分:0)
试试这个
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(myListBox);
DataTemplate yourDataTemplate = contentPresenter.ContentTemplate;
TextBox txtName= yourDataTemplate.FindName("vidList", contentPresenter)
as TextBox ;
if (txtName!= null)
{
// Do something with txtNamehere
}